-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Sparse doc values index for LogsDB host.name field
#120741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
65f02eb
1e14746
6476c15
47039a9
15ecf22
ffe0a2c
5cd8126
4b54de6
4b6b87d
db8374e
328e42b
3d27a95
4ce3758
6a452bf
faea308
457d14f
4909ecb
2e3a51e
1868134
e4f0184
3d7fdc2
24aa35d
16014a8
e0599ac
1254c7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| import org.apache.lucene.document.InvertableType; | ||
| import org.apache.lucene.document.SortedSetDocValuesField; | ||
| import org.apache.lucene.document.StoredField; | ||
| import org.apache.lucene.index.DocValuesSkipIndexType; | ||
| import org.apache.lucene.index.DocValuesType; | ||
| import org.apache.lucene.index.IndexOptions; | ||
| import org.apache.lucene.index.IndexReader; | ||
|
|
@@ -38,6 +39,8 @@ | |
| import org.elasticsearch.common.lucene.search.AutomatonQueries; | ||
| import org.elasticsearch.common.unit.Fuzziness; | ||
| import org.elasticsearch.core.Nullable; | ||
| import org.elasticsearch.index.IndexMode; | ||
| import org.elasticsearch.index.IndexSortConfig; | ||
| import org.elasticsearch.index.IndexVersion; | ||
| import org.elasticsearch.index.analysis.IndexAnalyzers; | ||
| import org.elasticsearch.index.analysis.NamedAnalyzer; | ||
|
|
@@ -87,9 +90,11 @@ public final class KeywordFieldMapper extends FieldMapper { | |
| private static final Logger logger = LogManager.getLogger(KeywordFieldMapper.class); | ||
|
|
||
| public static final String CONTENT_TYPE = "keyword"; | ||
| private static final String HOST_NAME = "host.name"; | ||
|
|
||
| public static class Defaults { | ||
| public static final FieldType FIELD_TYPE; | ||
| public static final FieldType FIELD_TYPE_WITH_SKIP_DOC_VALUES; | ||
|
|
||
| static { | ||
| FieldType ft = new FieldType(); | ||
|
|
@@ -100,6 +105,16 @@ public static class Defaults { | |
| FIELD_TYPE = freezeAndDeduplicateFieldType(ft); | ||
| } | ||
|
|
||
| static { | ||
| FieldType ft = new FieldType(); | ||
| ft.setTokenized(false); | ||
| ft.setOmitNorms(true); | ||
| ft.setIndexOptions(IndexOptions.NONE); | ||
| ft.setDocValuesType(DocValuesType.SORTED_SET); | ||
| ft.setDocValuesSkipIndexType(DocValuesSkipIndexType.RANGE); | ||
| FIELD_TYPE_WITH_SKIP_DOC_VALUES = freezeAndDeduplicateFieldType(ft); | ||
| } | ||
|
|
||
| public static final TextSearchInfo TEXT_SEARCH_INFO = new TextSearchInfo( | ||
| FIELD_TYPE, | ||
| null, | ||
|
|
@@ -154,7 +169,8 @@ public static final class Builder extends FieldMapper.DimensionBuilder { | |
| ); | ||
| private final Parameter<Integer> ignoreAbove; | ||
| private final int ignoreAboveDefault; | ||
|
|
||
| private final IndexSortConfig indexSortConfig; | ||
| private final IndexMode indexMode; | ||
| private final Parameter<String> indexOptions = TextParams.keywordIndexOptions(m -> toType(m).indexOptions); | ||
| private final Parameter<Boolean> hasNorms = TextParams.norms(false, m -> toType(m).fieldType.omitNorms() == false); | ||
| private final Parameter<SimilarityProvider> similarity = TextParams.similarity( | ||
|
|
@@ -189,7 +205,9 @@ public Builder(final String name, final MappingParserContext mappingParserContex | |
| mappingParserContext.getIndexAnalyzers(), | ||
| mappingParserContext.scriptCompiler(), | ||
| IGNORE_ABOVE_SETTING.get(mappingParserContext.getSettings()), | ||
| mappingParserContext.getIndexSettings().getIndexVersionCreated() | ||
| mappingParserContext.getIndexSettings().getIndexVersionCreated(), | ||
| mappingParserContext.getIndexSettings().getMode(), | ||
| mappingParserContext.getIndexSettings().getIndexSortConfig() | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -199,6 +217,18 @@ public Builder(final String name, final MappingParserContext mappingParserContex | |
| ScriptCompiler scriptCompiler, | ||
| int ignoreAboveDefault, | ||
| IndexVersion indexCreatedVersion | ||
| ) { | ||
| this(name, indexAnalyzers, scriptCompiler, ignoreAboveDefault, indexCreatedVersion, IndexMode.STANDARD, null); | ||
| } | ||
|
|
||
| private Builder( | ||
|
martijnvg marked this conversation as resolved.
|
||
| String name, | ||
| IndexAnalyzers indexAnalyzers, | ||
| ScriptCompiler scriptCompiler, | ||
| int ignoreAboveDefault, | ||
| IndexVersion indexCreatedVersion, | ||
| IndexMode indexMode, | ||
| IndexSortConfig indexSortConfig | ||
| ) { | ||
| super(name); | ||
| this.indexAnalyzers = indexAnalyzers; | ||
|
|
@@ -233,6 +263,8 @@ public Builder(final String name, final MappingParserContext mappingParserContex | |
| throw new IllegalArgumentException("[ignore_above] must be positive, got [" + v + "]"); | ||
| } | ||
| }); | ||
| this.indexSortConfig = indexSortConfig; | ||
| this.indexMode = indexMode; | ||
| } | ||
|
|
||
| public Builder(String name, IndexVersion indexCreatedVersion) { | ||
|
|
@@ -359,7 +391,7 @@ private KeywordFieldType buildFieldType(MapperBuilderContext context, FieldType | |
|
|
||
| @Override | ||
| public KeywordFieldMapper build(MapperBuilderContext context) { | ||
| FieldType fieldtype = new FieldType(Defaults.FIELD_TYPE); | ||
| FieldType fieldtype = resolveFieldType(indexSortConfig, indexMode, context.buildFullName(leafName())); | ||
| fieldtype.setOmitNorms(this.hasNorms.getValue() == false); | ||
| fieldtype.setIndexOptions(TextParams.toIndexOptions(this.indexed.getValue(), this.indexOptions.getValue())); | ||
| fieldtype.setStored(this.stored.getValue()); | ||
|
|
@@ -368,6 +400,9 @@ public KeywordFieldMapper build(MapperBuilderContext context) { | |
| // deduplicate in the common default case to save some memory | ||
| fieldtype = Defaults.FIELD_TYPE; | ||
| } | ||
| if (fieldtype.equals(Defaults.FIELD_TYPE_WITH_SKIP_DOC_VALUES)) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An optimization as above. |
||
| fieldtype = Defaults.FIELD_TYPE_WITH_SKIP_DOC_VALUES; | ||
| } | ||
| super.hasScript = script.get() != null; | ||
| super.onScriptError = onScriptError.getValue(); | ||
| return new KeywordFieldMapper( | ||
|
|
@@ -379,6 +414,31 @@ public KeywordFieldMapper build(MapperBuilderContext context) { | |
| this | ||
| ); | ||
| } | ||
|
|
||
| private FieldType resolveFieldType(final IndexSortConfig indexSortConfig, final IndexMode indexMode, final String fullFieldName) { | ||
| if (shouldUseDocValuesSparseIndex(indexSortConfig, indexMode, fullFieldName)) { | ||
| return new FieldType(Defaults.FIELD_TYPE_WITH_SKIP_DOC_VALUES); | ||
| } | ||
| return new FieldType(Defaults.FIELD_TYPE); | ||
| } | ||
|
|
||
| private boolean shouldUseDocValuesSparseIndex( | ||
|
martijnvg marked this conversation as resolved.
|
||
| final IndexSortConfig indexSortConfig, | ||
| final IndexMode indexMode, | ||
| final String fullFieldName | ||
| ) { | ||
| if (FieldMapper.DOC_VALUES_SPARSE_INDEX.isEnabled() == false) { | ||
| return false; | ||
| } | ||
| boolean isIndexedAndDocValuesDefault = indexed.isConfigured() || hasDocValues.isConfigured(); | ||
| boolean isNotIndexedAndHasDocValues = indexed.getValue() || hasDocValues.getValue() == false; | ||
| boolean isLogsDbMode = IndexMode.LOGSDB.equals(indexMode); | ||
| boolean isHostNameField = HOST_NAME.equals(fullFieldName); | ||
| boolean isPrimarySortField = indexSortConfig != null && indexSortConfig.hasPrimarySortOnField(HOST_NAME); | ||
|
|
||
| return (isIndexedAndDocValuesDefault || isNotIndexedAndHasDocValues) && isLogsDbMode && isHostNameField && isPrimarySortField; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to enable sparse index only if index has not been configured and doc values isn't disabled. So I think this is easier: ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| public static final TypeParser PARSER = createTypeParserWithLegacySupport(Builder::new); | ||
|
|
@@ -392,6 +452,9 @@ public static final class KeywordFieldType extends StringFieldType { | |
| private final FieldValues<String> scriptValues; | ||
| private final boolean isDimension; | ||
| private final boolean isSyntheticSource; | ||
| private final IndexMode indexMode; | ||
| private final IndexSortConfig indexSortConfig; | ||
| private final boolean hasDocValuesSparseIndex; | ||
|
|
||
| public KeywordFieldType( | ||
| String name, | ||
|
|
@@ -417,6 +480,9 @@ public KeywordFieldType( | |
| this.scriptValues = builder.scriptValues(); | ||
| this.isDimension = builder.dimension.getValue(); | ||
| this.isSyntheticSource = isSyntheticSource; | ||
| this.indexMode = builder.indexMode; | ||
| this.indexSortConfig = builder.indexSortConfig; | ||
| this.hasDocValuesSparseIndex = DocValuesSkipIndexType.NONE.equals(fieldType.docValuesSkipIndexType()) == false; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking this way we make sure the boolean value is correct even if new skip indices other than |
||
| } | ||
|
|
||
| public KeywordFieldType(String name, boolean isIndexed, boolean hasDocValues, Map<String, String> meta) { | ||
|
|
@@ -428,6 +494,9 @@ public KeywordFieldType(String name, boolean isIndexed, boolean hasDocValues, Ma | |
| this.scriptValues = null; | ||
| this.isDimension = false; | ||
| this.isSyntheticSource = false; | ||
| this.indexMode = IndexMode.STANDARD; | ||
| this.indexSortConfig = null; | ||
| this.hasDocValuesSparseIndex = false; | ||
| } | ||
|
|
||
| public KeywordFieldType(String name) { | ||
|
|
@@ -450,6 +519,9 @@ public KeywordFieldType(String name, FieldType fieldType) { | |
| this.scriptValues = null; | ||
| this.isDimension = false; | ||
| this.isSyntheticSource = false; | ||
| this.indexMode = IndexMode.STANDARD; | ||
| this.indexSortConfig = null; | ||
| this.hasDocValuesSparseIndex = DocValuesSkipIndexType.NONE.equals(fieldType.docValuesSkipIndexType()) == false; | ||
| } | ||
|
|
||
| public KeywordFieldType(String name, NamedAnalyzer analyzer) { | ||
|
|
@@ -461,6 +533,9 @@ public KeywordFieldType(String name, NamedAnalyzer analyzer) { | |
| this.scriptValues = null; | ||
| this.isDimension = false; | ||
| this.isSyntheticSource = false; | ||
| this.indexMode = IndexMode.STANDARD; | ||
| this.indexSortConfig = null; | ||
| this.hasDocValuesSparseIndex = false; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -851,6 +926,18 @@ public boolean hasScriptValues() { | |
| public boolean hasNormalizer() { | ||
| return normalizer != Lucene.KEYWORD_ANALYZER; | ||
| } | ||
|
|
||
| public IndexMode getIndexMode() { | ||
| return indexMode; | ||
| } | ||
|
|
||
| public IndexSortConfig getIndexSortConfig() { | ||
| return indexSortConfig; | ||
| } | ||
|
|
||
| public boolean hasDocValuesSparseIndex() { | ||
| return hasDocValuesSparseIndex; | ||
| } | ||
| } | ||
|
|
||
| private final boolean indexed; | ||
|
|
@@ -866,7 +953,8 @@ public boolean hasNormalizer() { | |
|
|
||
| private final IndexAnalyzers indexAnalyzers; | ||
| private final int ignoreAboveDefault; | ||
| private final int ignoreAbove; | ||
| private final IndexMode indexMode; | ||
| private final IndexSortConfig indexSortConfig; | ||
|
|
||
| private KeywordFieldMapper( | ||
| String simpleName, | ||
|
|
@@ -890,7 +978,8 @@ private KeywordFieldMapper( | |
| this.indexCreatedVersion = builder.indexCreatedVersion; | ||
| this.isSyntheticSource = isSyntheticSource; | ||
| this.ignoreAboveDefault = builder.ignoreAboveDefault; | ||
| this.ignoreAbove = builder.ignoreAbove.getValue(); | ||
| this.indexMode = builder.indexMode; | ||
| this.indexSortConfig = builder.indexSortConfig; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -1008,9 +1097,9 @@ public Map<String, NamedAnalyzer> indexAnalyzers() { | |
|
|
||
| @Override | ||
| public FieldMapper.Builder getMergeBuilder() { | ||
| return new Builder(leafName(), indexAnalyzers, scriptCompiler, ignoreAboveDefault, indexCreatedVersion).dimension( | ||
| fieldType().isDimension() | ||
| ).init(this); | ||
| return new Builder(leafName(), indexAnalyzers, scriptCompiler, ignoreAboveDefault, indexCreatedVersion, indexMode, indexSortConfig) | ||
| .dimension(fieldType().isDimension()) | ||
| .init(this); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.