Skip to content

Commit ecc423b

Browse files
authored
Revert "Sparse doc values index for LogsDB host.name field (elastic#120741)" (elastic#124803)
This reverts commit 1b6a080.
1 parent 6cd10c0 commit ecc423b

File tree

3 files changed

+9
-312
lines changed

3 files changed

+9
-312
lines changed

server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.elasticsearch.common.settings.Setting;
2222
import org.elasticsearch.common.settings.Setting.Property;
2323
import org.elasticsearch.common.util.CollectionUtils;
24-
import org.elasticsearch.common.util.FeatureFlag;
2524
import org.elasticsearch.common.util.Maps;
2625
import org.elasticsearch.common.xcontent.support.XContentMapValues;
2726
import org.elasticsearch.index.IndexMode;
@@ -64,7 +63,6 @@
6463
public abstract class FieldMapper extends Mapper {
6564
private static final Logger logger = LogManager.getLogger(FieldMapper.class);
6665

67-
public static final FeatureFlag DOC_VALUES_SPARSE_INDEX = new FeatureFlag("doc_values_sparse_index");
6866
public static final Setting<Boolean> IGNORE_MALFORMED_SETTING = Setting.boolSetting("index.mapping.ignore_malformed", settings -> {
6967
if (IndexSettings.MODE.get(settings) == IndexMode.LOGSDB
7068
&& IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings).onOrAfter(IndexVersions.ENABLE_IGNORE_MALFORMED_LOGSDB)) {
@@ -853,10 +851,6 @@ public boolean isConfigured() {
853851
return isSet && Objects.equals(value, getDefaultValue()) == false;
854852
}
855853

856-
public boolean isSet() {
857-
return isSet;
858-
}
859-
860854
/**
861855
* Allows the parameter to accept a {@code null} value
862856
*/

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

Lines changed: 9 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.apache.lucene.document.InvertableType;
1919
import org.apache.lucene.document.SortedSetDocValuesField;
2020
import org.apache.lucene.document.StoredField;
21-
import org.apache.lucene.index.DocValuesSkipIndexType;
2221
import org.apache.lucene.index.DocValuesType;
2322
import org.apache.lucene.index.IndexOptions;
2423
import org.apache.lucene.index.IndexReader;
@@ -39,10 +38,7 @@
3938
import org.elasticsearch.common.lucene.search.AutomatonQueries;
4039
import org.elasticsearch.common.unit.Fuzziness;
4140
import org.elasticsearch.core.Nullable;
42-
import org.elasticsearch.index.IndexMode;
43-
import org.elasticsearch.index.IndexSortConfig;
4441
import org.elasticsearch.index.IndexVersion;
45-
import org.elasticsearch.index.IndexVersions;
4642
import org.elasticsearch.index.analysis.IndexAnalyzers;
4743
import org.elasticsearch.index.analysis.NamedAnalyzer;
4844
import org.elasticsearch.index.fielddata.FieldData;
@@ -91,11 +87,9 @@ public final class KeywordFieldMapper extends FieldMapper {
9187
private static final Logger logger = LogManager.getLogger(KeywordFieldMapper.class);
9288

9389
public static final String CONTENT_TYPE = "keyword";
94-
private static final String HOST_NAME = "host.name";
9590

9691
public static class Defaults {
9792
public static final FieldType FIELD_TYPE;
98-
public static final FieldType FIELD_TYPE_WITH_SKIP_DOC_VALUES;
9993

10094
static {
10195
FieldType ft = new FieldType();
@@ -106,16 +100,6 @@ public static class Defaults {
106100
FIELD_TYPE = freezeAndDeduplicateFieldType(ft);
107101
}
108102

109-
static {
110-
FieldType ft = new FieldType();
111-
ft.setTokenized(false);
112-
ft.setOmitNorms(true);
113-
ft.setIndexOptions(IndexOptions.NONE);
114-
ft.setDocValuesType(DocValuesType.SORTED_SET);
115-
ft.setDocValuesSkipIndexType(DocValuesSkipIndexType.RANGE);
116-
FIELD_TYPE_WITH_SKIP_DOC_VALUES = freezeAndDeduplicateFieldType(ft);
117-
}
118-
119103
public static final TextSearchInfo TEXT_SEARCH_INFO = new TextSearchInfo(
120104
FIELD_TYPE,
121105
null,
@@ -170,8 +154,7 @@ public static final class Builder extends FieldMapper.DimensionBuilder {
170154
);
171155
private final Parameter<Integer> ignoreAbove;
172156
private final int ignoreAboveDefault;
173-
private final IndexSortConfig indexSortConfig;
174-
private final IndexMode indexMode;
157+
175158
private final Parameter<String> indexOptions = TextParams.keywordIndexOptions(m -> toType(m).indexOptions);
176159
private final Parameter<Boolean> hasNorms = TextParams.norms(false, m -> toType(m).fieldType.omitNorms() == false);
177160
private final Parameter<SimilarityProvider> similarity = TextParams.similarity(
@@ -206,9 +189,7 @@ public Builder(final String name, final MappingParserContext mappingParserContex
206189
mappingParserContext.getIndexAnalyzers(),
207190
mappingParserContext.scriptCompiler(),
208191
IGNORE_ABOVE_SETTING.get(mappingParserContext.getSettings()),
209-
mappingParserContext.getIndexSettings().getIndexVersionCreated(),
210-
mappingParserContext.getIndexSettings().getMode(),
211-
mappingParserContext.getIndexSettings().getIndexSortConfig()
192+
mappingParserContext.getIndexSettings().getIndexVersionCreated()
212193
);
213194
}
214195

@@ -218,18 +199,6 @@ public Builder(final String name, final MappingParserContext mappingParserContex
218199
ScriptCompiler scriptCompiler,
219200
int ignoreAboveDefault,
220201
IndexVersion indexCreatedVersion
221-
) {
222-
this(name, indexAnalyzers, scriptCompiler, ignoreAboveDefault, indexCreatedVersion, IndexMode.STANDARD, null);
223-
}
224-
225-
private Builder(
226-
String name,
227-
IndexAnalyzers indexAnalyzers,
228-
ScriptCompiler scriptCompiler,
229-
int ignoreAboveDefault,
230-
IndexVersion indexCreatedVersion,
231-
IndexMode indexMode,
232-
IndexSortConfig indexSortConfig
233202
) {
234203
super(name);
235204
this.indexAnalyzers = indexAnalyzers;
@@ -264,8 +233,6 @@ private Builder(
264233
throw new IllegalArgumentException("[ignore_above] must be positive, got [" + v + "]");
265234
}
266235
});
267-
this.indexSortConfig = indexSortConfig;
268-
this.indexMode = indexMode;
269236
}
270237

271238
public Builder(String name, IndexVersion indexCreatedVersion) {
@@ -392,21 +359,15 @@ private KeywordFieldType buildFieldType(MapperBuilderContext context, FieldType
392359

393360
@Override
394361
public KeywordFieldMapper build(MapperBuilderContext context) {
395-
FieldType fieldtype = resolveFieldType(indexCreatedVersion, indexSortConfig, indexMode, context.buildFullName(leafName()));
362+
FieldType fieldtype = new FieldType(Defaults.FIELD_TYPE);
396363
fieldtype.setOmitNorms(this.hasNorms.getValue() == false);
364+
fieldtype.setIndexOptions(TextParams.toIndexOptions(this.indexed.getValue(), this.indexOptions.getValue()));
397365
fieldtype.setStored(this.stored.getValue());
398366
fieldtype.setDocValuesType(this.hasDocValues.getValue() ? DocValuesType.SORTED_SET : DocValuesType.NONE);
399-
if (fieldtype.equals(Defaults.FIELD_TYPE_WITH_SKIP_DOC_VALUES) == false) {
400-
// NOTE: override index options only if we are not using a sparse doc values index (and we use an inverted index)
401-
fieldtype.setIndexOptions(TextParams.toIndexOptions(this.indexed.getValue(), this.indexOptions.getValue()));
402-
}
403367
if (fieldtype.equals(Defaults.FIELD_TYPE)) {
404368
// deduplicate in the common default case to save some memory
405369
fieldtype = Defaults.FIELD_TYPE;
406370
}
407-
if (fieldtype.equals(Defaults.FIELD_TYPE_WITH_SKIP_DOC_VALUES)) {
408-
fieldtype = Defaults.FIELD_TYPE_WITH_SKIP_DOC_VALUES;
409-
}
410371
super.hasScript = script.get() != null;
411372
super.onScriptError = onScriptError.getValue();
412373
return new KeywordFieldMapper(
@@ -418,63 +379,6 @@ public KeywordFieldMapper build(MapperBuilderContext context) {
418379
this
419380
);
420381
}
421-
422-
private FieldType resolveFieldType(
423-
final IndexVersion indexCreatedVersion,
424-
final IndexSortConfig indexSortConfig,
425-
final IndexMode indexMode,
426-
final String fullFieldName
427-
) {
428-
if (FieldMapper.DOC_VALUES_SPARSE_INDEX.isEnabled()
429-
&& indexCreatedVersion.onOrAfter(IndexVersions.HOSTNAME_DOC_VALUES_SPARSE_INDEX)
430-
&& shouldUseDocValuesSparseIndex(indexSortConfig, indexMode, fullFieldName)) {
431-
return new FieldType(Defaults.FIELD_TYPE_WITH_SKIP_DOC_VALUES);
432-
}
433-
return new FieldType(Defaults.FIELD_TYPE);
434-
}
435-
436-
/**
437-
* Determines whether to use a sparse index representation for doc values.
438-
*
439-
* <p>If the field is explicitly indexed by setting {@code index: true}, we do not use
440-
* a sparse doc values index but instead rely on the inverted index, as is typically
441-
* the case for keyword fields.</p>
442-
*
443-
* <p>This method checks several conditions to decide if the sparse index format
444-
* should be applied:</p>
445-
*
446-
* <ul>
447-
* <li>Returns {@code false} immediately if the field is explicitly indexed.</li>
448-
* <li>Ensures the field is not explicitly configured as indexed (i.e., {@code index} has its default value).</li>
449-
* <li>Requires doc values to be enabled.</li>
450-
* <li>Index mode must be {@link IndexMode#LOGSDB}.</li>
451-
* <li>Field name must be {@code host.name}.</li>
452-
* <li>The {@code host.name} field must be a primary sort field.</li>
453-
* </ul>
454-
*
455-
* <p>Returns {@code true} if all conditions are met, indicating that sparse doc values
456-
* should be used. Otherwise, returns {@code false}.</p>
457-
*
458-
* @param indexSortConfig The index sort configuration, used to check primary sorting.
459-
* @param indexMode The mode of the index, which must be {@link IndexMode#LOGSDB}.
460-
* @param fullFieldName The name of the field being checked, which must be {@code host.name}.
461-
* @return {@code true} if sparse doc values should be used, otherwise {@code false}.
462-
*/
463-
464-
private boolean shouldUseDocValuesSparseIndex(
465-
final IndexSortConfig indexSortConfig,
466-
final IndexMode indexMode,
467-
final String fullFieldName
468-
) {
469-
if (indexed.isSet() && indexed.getValue()) {
470-
return false;
471-
}
472-
return indexed.isConfigured() == false
473-
&& hasDocValues.getValue()
474-
&& IndexMode.LOGSDB.equals(indexMode)
475-
&& HOST_NAME.equals(fullFieldName)
476-
&& (indexSortConfig != null && indexSortConfig.hasPrimarySortOnField(HOST_NAME));
477-
}
478382
}
479383

480384
public static final TypeParser PARSER = createTypeParserWithLegacySupport(Builder::new);
@@ -488,9 +392,6 @@ public static final class KeywordFieldType extends StringFieldType {
488392
private final FieldValues<String> scriptValues;
489393
private final boolean isDimension;
490394
private final boolean isSyntheticSource;
491-
private final IndexMode indexMode;
492-
private final IndexSortConfig indexSortConfig;
493-
private final boolean hasDocValuesSparseIndex;
494395

495396
public KeywordFieldType(
496397
String name,
@@ -516,9 +417,6 @@ public KeywordFieldType(
516417
this.scriptValues = builder.scriptValues();
517418
this.isDimension = builder.dimension.getValue();
518419
this.isSyntheticSource = isSyntheticSource;
519-
this.indexMode = builder.indexMode;
520-
this.indexSortConfig = builder.indexSortConfig;
521-
this.hasDocValuesSparseIndex = DocValuesSkipIndexType.NONE.equals(fieldType.docValuesSkipIndexType()) == false;
522420
}
523421

524422
public KeywordFieldType(String name, boolean isIndexed, boolean hasDocValues, Map<String, String> meta) {
@@ -530,9 +428,6 @@ public KeywordFieldType(String name, boolean isIndexed, boolean hasDocValues, Ma
530428
this.scriptValues = null;
531429
this.isDimension = false;
532430
this.isSyntheticSource = false;
533-
this.indexMode = IndexMode.STANDARD;
534-
this.indexSortConfig = null;
535-
this.hasDocValuesSparseIndex = false;
536431
}
537432

538433
public KeywordFieldType(String name) {
@@ -555,9 +450,6 @@ public KeywordFieldType(String name, FieldType fieldType) {
555450
this.scriptValues = null;
556451
this.isDimension = false;
557452
this.isSyntheticSource = false;
558-
this.indexMode = IndexMode.STANDARD;
559-
this.indexSortConfig = null;
560-
this.hasDocValuesSparseIndex = DocValuesSkipIndexType.NONE.equals(fieldType.docValuesSkipIndexType()) == false;
561453
}
562454

563455
public KeywordFieldType(String name, NamedAnalyzer analyzer) {
@@ -569,9 +461,6 @@ public KeywordFieldType(String name, NamedAnalyzer analyzer) {
569461
this.scriptValues = null;
570462
this.isDimension = false;
571463
this.isSyntheticSource = false;
572-
this.indexMode = IndexMode.STANDARD;
573-
this.indexSortConfig = null;
574-
this.hasDocValuesSparseIndex = false;
575464
}
576465

577466
@Override
@@ -962,18 +851,6 @@ public boolean hasScriptValues() {
962851
public boolean hasNormalizer() {
963852
return normalizer != Lucene.KEYWORD_ANALYZER;
964853
}
965-
966-
public IndexMode getIndexMode() {
967-
return indexMode;
968-
}
969-
970-
public IndexSortConfig getIndexSortConfig() {
971-
return indexSortConfig;
972-
}
973-
974-
public boolean hasDocValuesSparseIndex() {
975-
return hasDocValuesSparseIndex;
976-
}
977854
}
978855

979856
private final boolean indexed;
@@ -989,8 +866,7 @@ public boolean hasDocValuesSparseIndex() {
989866

990867
private final IndexAnalyzers indexAnalyzers;
991868
private final int ignoreAboveDefault;
992-
private final IndexMode indexMode;
993-
private final IndexSortConfig indexSortConfig;
869+
private final int ignoreAbove;
994870

995871
private KeywordFieldMapper(
996872
String simpleName,
@@ -1014,8 +890,7 @@ private KeywordFieldMapper(
1014890
this.indexCreatedVersion = builder.indexCreatedVersion;
1015891
this.isSyntheticSource = isSyntheticSource;
1016892
this.ignoreAboveDefault = builder.ignoreAboveDefault;
1017-
this.indexMode = builder.indexMode;
1018-
this.indexSortConfig = builder.indexSortConfig;
893+
this.ignoreAbove = builder.ignoreAbove.getValue();
1019894
}
1020895

1021896
@Override
@@ -1133,9 +1008,9 @@ public Map<String, NamedAnalyzer> indexAnalyzers() {
11331008

11341009
@Override
11351010
public FieldMapper.Builder getMergeBuilder() {
1136-
return new Builder(leafName(), indexAnalyzers, scriptCompiler, ignoreAboveDefault, indexCreatedVersion, indexMode, indexSortConfig)
1137-
.dimension(fieldType().isDimension())
1138-
.init(this);
1011+
return new Builder(leafName(), indexAnalyzers, scriptCompiler, ignoreAboveDefault, indexCreatedVersion).dimension(
1012+
fieldType().isDimension()
1013+
).init(this);
11391014
}
11401015

11411016
@Override

0 commit comments

Comments
 (0)