Skip to content

Commit 93ca9ad

Browse files
authored
Enable New Semantic Text Format Only On Newly Created Indices (#121556) (#121574)
(cherry picked from commit d23699f)
1 parent f498c70 commit 93ca9ad

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

docs/changelog/121556.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121556
2+
summary: Enable New Semantic Text Format Only On Newly Created Indices
3+
area: Mapping
4+
type: bug
5+
issues: []

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.cluster.metadata.IndexMetadata;
1616
import org.elasticsearch.common.settings.Setting;
1717
import org.elasticsearch.common.settings.Settings;
18+
import org.elasticsearch.index.IndexVersion;
1819
import org.elasticsearch.index.IndexVersions;
1920
import org.elasticsearch.index.query.SearchExecutionContext;
2021

@@ -41,6 +42,10 @@ public abstract class InferenceMetadataFieldsMapper extends MetadataFieldMapper
4142
Setting.Property.InternalIndex
4243
);
4344

45+
// Check index version SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP because that index version was added in the same serverless promotion
46+
// where the new format was enabled by default
47+
public static final IndexVersion USE_NEW_SEMANTIC_TEXT_FORMAT_BY_DEFAULT = IndexVersions.SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP;
48+
4449
public static final String NAME = "_inference_fields";
4550
public static final String CONTENT_TYPE = "_inference_fields";
4651

@@ -86,10 +91,12 @@ public abstract ValueFetcher valueFetcher(
8691
*/
8792
public static boolean isEnabled(Settings settings) {
8893
var version = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings);
89-
if (version.before(IndexVersions.INFERENCE_METADATA_FIELDS)
90-
&& version.between(IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT, IndexVersions.UPGRADE_TO_LUCENE_10_0_0) == false) {
94+
if ((version.before(IndexVersions.INFERENCE_METADATA_FIELDS)
95+
&& version.between(IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT, IndexVersions.UPGRADE_TO_LUCENE_10_0_0) == false)
96+
|| (version.before(USE_NEW_SEMANTIC_TEXT_FORMAT_BY_DEFAULT) && USE_LEGACY_SEMANTIC_TEXT_FORMAT.exists(settings) == false)) {
9197
return false;
9298
}
99+
93100
return USE_LEGACY_SEMANTIC_TEXT_FORMAT.get(settings) == false;
94101
}
95102

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticInferenceMetadataFieldsMapperTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ public void testIsEnabled() {
5555
assertTrue(InferenceMetadataFieldsMapper.isEnabled(settings));
5656
}
5757

58+
public void testIsEnabledByDefault() {
59+
var settings = Settings.builder()
60+
.put(
61+
IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(),
62+
IndexVersionUtils.getPreviousVersion(InferenceMetadataFieldsMapper.USE_NEW_SEMANTIC_TEXT_FORMAT_BY_DEFAULT)
63+
)
64+
.build();
65+
assertFalse(InferenceMetadataFieldsMapper.isEnabled(settings));
66+
67+
settings = Settings.builder()
68+
.put(
69+
IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(),
70+
InferenceMetadataFieldsMapper.USE_NEW_SEMANTIC_TEXT_FORMAT_BY_DEFAULT
71+
)
72+
.build();
73+
assertTrue(InferenceMetadataFieldsMapper.isEnabled(settings));
74+
}
75+
5876
@Override
5977
public void testFieldHasValue() {
6078
assertTrue(

0 commit comments

Comments
 (0)