Skip to content

Commit

Permalink
fix: enable sparse index if field is indexed nad has doc values
Browse files Browse the repository at this point in the history
  • Loading branch information
salvatore-campagna committed Jan 23, 2025
1 parent 1e14746 commit 6476c15
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private boolean shouldUseDocValuesSparseIndex(
final IndexMode indexMode,
final String fullFieldName
) {
return areDefaultSettingsUsed()
return (areDefaultSettingsUsed() || isNotIndexedAndHasDocValues())
&& isLogsDbMode(indexMode)
&& isHostNameField(fullFieldName)
&& isPrimarySortField(indexSortConfig);
Expand All @@ -435,6 +435,10 @@ private boolean areDefaultSettingsUsed() {
return indexed.isConfigured() == false && hasDocValues.isConfigured() == false;
}

private boolean isNotIndexedAndHasDocValues() {
return indexed.getValue() == false && hasDocValues.getValue();
}

private boolean isLogsDbMode(final IndexMode indexMode) {
return IndexMode.LOGSDB.equals(indexMode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,4 +876,71 @@ public void testFieldTypeDefault_LogsDbMode_NonSortField() throws IOException {
final KeywordFieldMapper mapper = (KeywordFieldMapper) mapperService.documentMapper().mappers().getMapper("host.name");
assertFalse(mapper.fieldType().hasDocValuesSparseIndex());
}

public void testFieldTypeWithSkipDocValues_IndexedFalseDocValuesTrue() throws IOException {
final MapperService mapperService = createMapperService(
Settings.builder()
.put(IndexSettings.MODE.getKey(), IndexMode.LOGSDB.name())
.put(IndexSortConfig.INDEX_SORT_FIELD_SETTING.getKey(), "host.name")
.build(),
mapping(b -> {
b.startObject("host.name");
b.field("type", "keyword");
b.field("index", false);
b.field("doc_values", true);
b.endObject();
})
);

final KeywordFieldMapper mapper = (KeywordFieldMapper) mapperService.documentMapper().mappers().getMapper("host.name");
assertTrue(mapper.fieldType().hasDocValuesSparseIndex());
}

public void testFieldTypeDefault_IndexedFalseDocValuesFalse() throws IOException {
final MapperService mapperService = createMapperService(
Settings.builder().put(IndexSettings.MODE.getKey(), IndexMode.LOGSDB.name()).build(),
mapping(b -> {
b.startObject("host.name");
b.field("type", "keyword");
b.field("index", false);
b.field("doc_values", false);
b.endObject();
})
);

final KeywordFieldMapper mapper = (KeywordFieldMapper) mapperService.documentMapper().mappers().getMapper("host.name");
assertFalse(mapper.fieldType().hasDocValuesSparseIndex());
}

public void testFieldTypeDefault_IndexedTrueDocValuesTrue() throws IOException {
final MapperService mapperService = createMapperService(
Settings.builder().put(IndexSettings.MODE.getKey(), IndexMode.LOGSDB.name()).build(),
mapping(b -> {
b.startObject("host.name");
b.field("type", "keyword");
b.field("index", true);
b.field("doc_values", true);
b.endObject();
})
);

final KeywordFieldMapper mapper = (KeywordFieldMapper) mapperService.documentMapper().mappers().getMapper("host.name");
assertFalse(mapper.fieldType().hasDocValuesSparseIndex());
}

public void testFieldTypeDefault_StandardModeIndexedFalseDocValuesTrue() throws IOException {
final MapperService mapperService = createMapperService(
Settings.builder().put(IndexSettings.MODE.getKey(), IndexMode.STANDARD.name()).build(),
mapping(b -> {
b.startObject("host.name");
b.field("type", "keyword");
b.field("index", false);
b.field("doc_values", true);
b.endObject();
})
);

final KeywordFieldMapper mapper = (KeywordFieldMapper) mapperService.documentMapper().mappers().getMapper("host.name");
assertFalse(mapper.fieldType().hasDocValuesSparseIndex());
}
}

0 comments on commit 6476c15

Please sign in to comment.