Update multi field stored by default index version check (#129386)

Relates to #129126
This commit is contained in:
Martijn van Groningen 2025-06-17 12:20:38 +02:00 committed by GitHub
parent 3f9bf9a6b8
commit a0cc698fa2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 3 deletions

View file

@ -33,7 +33,6 @@ import org.elasticsearch.common.CheckedIntFunction;
import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.analysis.IndexAnalyzers; import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.fielddata.FieldDataContext; import org.elasticsearch.index.fielddata.FieldDataContext;
@ -71,6 +70,8 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import static org.elasticsearch.index.mapper.TextFieldMapper.Builder.multiFieldsNotStoredByDefaultIndexVersionCheck;
/** /**
* A {@link FieldMapper} for full-text fields that only indexes * A {@link FieldMapper} for full-text fields that only indexes
* {@link IndexOptions#DOCS} and runs positional queries by looking at the * {@link IndexOptions#DOCS} and runs positional queries by looking at the
@ -140,7 +141,7 @@ public class MatchOnlyTextFieldMapper extends FieldMapper {
public MatchOnlyTextFieldMapper build(MapperBuilderContext context) { public MatchOnlyTextFieldMapper build(MapperBuilderContext context) {
MatchOnlyTextFieldType tft = buildFieldType(context); MatchOnlyTextFieldType tft = buildFieldType(context);
final boolean storeSource; final boolean storeSource;
if (indexCreatedVersion.onOrAfter(IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED)) { if (multiFieldsNotStoredByDefaultIndexVersionCheck(indexCreatedVersion)) {
storeSource = context.isSourceSynthetic() storeSource = context.isSourceSynthetic()
&& withinMultiField == false && withinMultiField == false
&& multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false; && multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false;

View file

@ -142,6 +142,7 @@ public class IndexVersions {
public static final IndexVersion DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ_BACKPORT_8_X = def(8_530_0_00, Version.LUCENE_9_12_1); public static final IndexVersion DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ_BACKPORT_8_X = def(8_530_0_00, Version.LUCENE_9_12_1);
public static final IndexVersion SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X = def(8_531_0_00, Version.LUCENE_9_12_1); public static final IndexVersion SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X = def(8_531_0_00, Version.LUCENE_9_12_1);
public static final IndexVersion INDEX_INT_SORT_INT_TYPE_8_19 = def(8_532_0_00, Version.LUCENE_9_12_1); public static final IndexVersion INDEX_INT_SORT_INT_TYPE_8_19 = def(8_532_0_00, Version.LUCENE_9_12_1);
public static final IndexVersion MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED_8_19 = def(8_533_0_00, Version.LUCENE_9_12_1);
public static final IndexVersion UPGRADE_TO_LUCENE_10_0_0 = def(9_000_0_00, Version.LUCENE_10_0_0); public static final IndexVersion UPGRADE_TO_LUCENE_10_0_0 = def(9_000_0_00, Version.LUCENE_10_0_0);
public static final IndexVersion LOGSDB_DEFAULT_IGNORE_DYNAMIC_BEYOND_LIMIT = def(9_001_0_00, Version.LUCENE_10_0_0); public static final IndexVersion LOGSDB_DEFAULT_IGNORE_DYNAMIC_BEYOND_LIMIT = def(9_001_0_00, Version.LUCENE_10_0_0);
public static final IndexVersion TIME_BASED_K_ORDERED_DOC_ID = def(9_002_0_00, Version.LUCENE_10_0_0); public static final IndexVersion TIME_BASED_K_ORDERED_DOC_ID = def(9_002_0_00, Version.LUCENE_10_0_0);

View file

@ -311,7 +311,7 @@ public final class TextFieldMapper extends FieldMapper {
// Note that if current builder is a multi field, then we don't need to store, given that responsibility lies with parent field // Note that if current builder is a multi field, then we don't need to store, given that responsibility lies with parent field
this.withinMultiField = withinMultiField; this.withinMultiField = withinMultiField;
this.store = Parameter.storeParam(m -> ((TextFieldMapper) m).store, () -> { this.store = Parameter.storeParam(m -> ((TextFieldMapper) m).store, () -> {
if (indexCreatedVersion.onOrAfter(IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED)) { if (multiFieldsNotStoredByDefaultIndexVersionCheck(indexCreatedVersion)) {
return isSyntheticSourceEnabled return isSyntheticSourceEnabled
&& this.withinMultiField == false && this.withinMultiField == false
&& multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false; && multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false;
@ -329,6 +329,14 @@ public final class TextFieldMapper extends FieldMapper {
this.isSyntheticSourceEnabled = isSyntheticSourceEnabled; this.isSyntheticSourceEnabled = isSyntheticSourceEnabled;
} }
public static boolean multiFieldsNotStoredByDefaultIndexVersionCheck(IndexVersion indexCreatedVersion) {
return indexCreatedVersion.onOrAfter(IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED)
|| indexCreatedVersion.between(
IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED_8_19,
IndexVersions.UPGRADE_TO_LUCENE_10_0_0
);
}
public Builder index(boolean index) { public Builder index(boolean index) {
this.index.setValue(index); this.index.setValue(index);
return this; return this;