Skip to content

Commit 5eba99c

Browse files
committed
Use alternate approach
1 parent 89fa610 commit 5eba99c

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@ public abstract class InferenceMetadataFieldsMapper extends MetadataFieldMapper
3636
*/
3737
public static final Setting<Boolean> USE_LEGACY_SEMANTIC_TEXT_FORMAT = Setting.boolSetting(
3838
"index.mapping.semantic_text.use_legacy_format",
39-
s -> {
40-
// Check index version SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP because that index version was added in the same serverless promotion
41-
// where the new format was enabled by default
42-
IndexVersion indexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(s);
43-
return Boolean.toString(indexVersion.before(IndexVersions.SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP));
44-
},
39+
false,
4540
Setting.Property.Final,
4641
Setting.Property.IndexScope,
4742
Setting.Property.InternalIndex
4843
);
4944

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_FORMAT_BY_DEFAULT = IndexVersions.SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP;
48+
5049
public static final String NAME = "_inference_fields";
5150
public static final String CONTENT_TYPE = "_inference_fields";
5251

@@ -92,10 +91,12 @@ public abstract ValueFetcher valueFetcher(
9291
*/
9392
public static boolean isEnabled(Settings settings) {
9493
var version = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings);
95-
if (version.before(IndexVersions.INFERENCE_METADATA_FIELDS)
96-
&& 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_FORMAT_BY_DEFAULT) && USE_LEGACY_SEMANTIC_TEXT_FORMAT.exists(settings) == false)) {
9797
return false;
9898
}
99+
99100
return USE_LEGACY_SEMANTIC_TEXT_FORMAT.get(settings) == false;
100101
}
101102

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,16 @@ public void testIsEnabled() {
5656
}
5757

5858
public void testIsEnabledByDefault() {
59-
// Check index version SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP because that index version was added in the same serverless promotion
60-
// where the new format was enabled by default
6159
var settings = Settings.builder()
6260
.put(
6361
IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(),
64-
IndexVersionUtils.getPreviousVersion(IndexVersions.SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP)
62+
IndexVersionUtils.getPreviousVersion(InferenceMetadataFieldsMapper.USE_NEW_FORMAT_BY_DEFAULT)
6563
)
6664
.build();
6765
assertFalse(InferenceMetadataFieldsMapper.isEnabled(settings));
6866

6967
settings = Settings.builder()
70-
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), IndexVersions.SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP)
68+
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), InferenceMetadataFieldsMapper.USE_NEW_FORMAT_BY_DEFAULT)
7169
.build();
7270
assertTrue(InferenceMetadataFieldsMapper.isEnabled(settings));
7371
}

0 commit comments

Comments
 (0)