Skip to content

Commit 5087478

Browse files
committed
gate new behaviour behind an index version
1 parent 4c8047c commit 5087478

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
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;
3637
import org.elasticsearch.index.analysis.IndexAnalyzers;
3738
import org.elasticsearch.index.analysis.NamedAnalyzer;
3839
import org.elasticsearch.index.fielddata.FieldDataContext;
@@ -136,9 +137,14 @@ private MatchOnlyTextFieldType buildFieldType(MapperBuilderContext context) {
136137
@Override
137138
public MatchOnlyTextFieldMapper build(MapperBuilderContext context) {
138139
MatchOnlyTextFieldType tft = buildFieldType(context);
139-
boolean storeSource = context.isSourceSynthetic()
140-
&& withinMultiField == false
141-
&& multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false;
140+
final boolean storeSource;
141+
if (indexCreatedVersion.onOrAfter(IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED)) {
142+
storeSource = context.isSourceSynthetic()
143+
&& withinMultiField == false
144+
&& multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false;
145+
} else {
146+
storeSource = context.isSourceSynthetic();
147+
}
142148
return new MatchOnlyTextFieldMapper(leafName(), Defaults.FIELD_TYPE, tft, builderParams(this, context), storeSource, this);
143149
}
144150
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ private static Version parseUnchecked(String version) {
171171
public static final IndexVersion DEFAULT_TO_ACORN_HNSW_FILTER_HEURISTIC = def(9_026_0_00, Version.LUCENE_10_2_1);
172172
public static final IndexVersion SEQ_NO_WITHOUT_POINTS = def(9_027_0_00, Version.LUCENE_10_2_1);
173173
public static final IndexVersion INDEX_INT_SORT_INT_TYPE = def(9_028_0_00, Version.LUCENE_10_2_1);
174+
public static final IndexVersion MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED = def(9_029_0_00, Version.LUCENE_10_2_1);
174175

175176
/*
176177
* STOP! READ THIS FIRST! No, really,

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,15 @@ public Builder(
307307
//
308308
// If 'store' parameter was explicitly provided we'll reject the request.
309309
// Note that if current builder is a multi field, then we don't need to store, given that responsibility lies with parent field
310-
this.store = Parameter.storeParam(
311-
m -> ((TextFieldMapper) m).store,
312-
() -> isSyntheticSourceEnabled
313-
&& this.withinMultiField == false
314-
&& multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false
315-
);
310+
this.store = Parameter.storeParam(m -> ((TextFieldMapper) m).store, () -> {
311+
if (indexCreatedVersion.onOrAfter(IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED)) {
312+
return isSyntheticSourceEnabled
313+
&& this.withinMultiField == false
314+
&& multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false;
315+
} else {
316+
return isSyntheticSourceEnabled;
317+
}
318+
});
316319
this.indexCreatedVersion = indexCreatedVersion;
317320
this.analyzers = new TextParams.Analyzers(
318321
indexAnalyzers,

0 commit comments

Comments
 (0)