Skip to content

Commit a0cc698

Browse files
authored
Update multi field stored by default index version check (#129386)
Relates to #129126
1 parent 3f9bf9a commit a0cc698

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.elasticsearch.common.lucene.Lucene;
3434
import org.elasticsearch.common.unit.Fuzziness;
3535
import org.elasticsearch.index.IndexVersion;
36-
import org.elasticsearch.index.IndexVersions;
3736
import org.elasticsearch.index.analysis.IndexAnalyzers;
3837
import org.elasticsearch.index.analysis.NamedAnalyzer;
3938
import org.elasticsearch.index.fielddata.FieldDataContext;
@@ -71,6 +70,8 @@
7170
import java.util.Objects;
7271
import java.util.Set;
7372

73+
import static org.elasticsearch.index.mapper.TextFieldMapper.Builder.multiFieldsNotStoredByDefaultIndexVersionCheck;
74+
7475
/**
7576
* A {@link FieldMapper} for full-text fields that only indexes
7677
* {@link IndexOptions#DOCS} and runs positional queries by looking at the
@@ -140,7 +141,7 @@ private MatchOnlyTextFieldType buildFieldType(MapperBuilderContext context) {
140141
public MatchOnlyTextFieldMapper build(MapperBuilderContext context) {
141142
MatchOnlyTextFieldType tft = buildFieldType(context);
142143
final boolean storeSource;
143-
if (indexCreatedVersion.onOrAfter(IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED)) {
144+
if (multiFieldsNotStoredByDefaultIndexVersionCheck(indexCreatedVersion)) {
144145
storeSource = context.isSourceSynthetic()
145146
&& withinMultiField == false
146147
&& multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false;

server/src/main/java/org/elasticsearch/index/IndexVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ private static Version parseUnchecked(String version) {
142142
public static final IndexVersion DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ_BACKPORT_8_X = def(8_530_0_00, Version.LUCENE_9_12_1);
143143
public static final IndexVersion SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X = def(8_531_0_00, Version.LUCENE_9_12_1);
144144
public static final IndexVersion INDEX_INT_SORT_INT_TYPE_8_19 = def(8_532_0_00, Version.LUCENE_9_12_1);
145+
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);
145146
public static final IndexVersion UPGRADE_TO_LUCENE_10_0_0 = def(9_000_0_00, Version.LUCENE_10_0_0);
146147
public static final IndexVersion LOGSDB_DEFAULT_IGNORE_DYNAMIC_BEYOND_LIMIT = def(9_001_0_00, Version.LUCENE_10_0_0);
147148
public static final IndexVersion TIME_BASED_K_ORDERED_DOC_ID = def(9_002_0_00, Version.LUCENE_10_0_0);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public Builder(
311311
// Note that if current builder is a multi field, then we don't need to store, given that responsibility lies with parent field
312312
this.withinMultiField = withinMultiField;
313313
this.store = Parameter.storeParam(m -> ((TextFieldMapper) m).store, () -> {
314-
if (indexCreatedVersion.onOrAfter(IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED)) {
314+
if (multiFieldsNotStoredByDefaultIndexVersionCheck(indexCreatedVersion)) {
315315
return isSyntheticSourceEnabled
316316
&& this.withinMultiField == false
317317
&& multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false;
@@ -329,6 +329,14 @@ public Builder(
329329
this.isSyntheticSourceEnabled = isSyntheticSourceEnabled;
330330
}
331331

332+
public static boolean multiFieldsNotStoredByDefaultIndexVersionCheck(IndexVersion indexCreatedVersion) {
333+
return indexCreatedVersion.onOrAfter(IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED)
334+
|| indexCreatedVersion.between(
335+
IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED_8_19,
336+
IndexVersions.UPGRADE_TO_LUCENE_10_0_0
337+
);
338+
}
339+
332340
public Builder index(boolean index) {
333341
this.index.setValue(index);
334342
return this;

0 commit comments

Comments
 (0)