Skip to content

Commit

Permalink
Enable New Semantic Text Format Only On Newly Created Indices (#121556)…
Browse files Browse the repository at this point in the history
… (#121574)

(cherry picked from commit d23699f)
  • Loading branch information
Mikep86 authored Feb 4, 2025
1 parent f498c70 commit 93ca9ad
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/121556.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 121556
summary: Enable New Semantic Text Format Only On Newly Created Indices
area: Mapping
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.query.SearchExecutionContext;

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

// Check index version SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP because that index version was added in the same serverless promotion
// where the new format was enabled by default
public static final IndexVersion USE_NEW_SEMANTIC_TEXT_FORMAT_BY_DEFAULT = IndexVersions.SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP;

public static final String NAME = "_inference_fields";
public static final String CONTENT_TYPE = "_inference_fields";

Expand Down Expand Up @@ -86,10 +91,12 @@ public abstract ValueFetcher valueFetcher(
*/
public static boolean isEnabled(Settings settings) {
var version = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings);
if (version.before(IndexVersions.INFERENCE_METADATA_FIELDS)
&& version.between(IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT, IndexVersions.UPGRADE_TO_LUCENE_10_0_0) == false) {
if ((version.before(IndexVersions.INFERENCE_METADATA_FIELDS)
&& version.between(IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT, IndexVersions.UPGRADE_TO_LUCENE_10_0_0) == false)
|| (version.before(USE_NEW_SEMANTIC_TEXT_FORMAT_BY_DEFAULT) && USE_LEGACY_SEMANTIC_TEXT_FORMAT.exists(settings) == false)) {
return false;
}

return USE_LEGACY_SEMANTIC_TEXT_FORMAT.get(settings) == false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ public void testIsEnabled() {
assertTrue(InferenceMetadataFieldsMapper.isEnabled(settings));
}

public void testIsEnabledByDefault() {
var settings = Settings.builder()
.put(
IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(),
IndexVersionUtils.getPreviousVersion(InferenceMetadataFieldsMapper.USE_NEW_SEMANTIC_TEXT_FORMAT_BY_DEFAULT)
)
.build();
assertFalse(InferenceMetadataFieldsMapper.isEnabled(settings));

settings = Settings.builder()
.put(
IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(),
InferenceMetadataFieldsMapper.USE_NEW_SEMANTIC_TEXT_FORMAT_BY_DEFAULT
)
.build();
assertTrue(InferenceMetadataFieldsMapper.isEnabled(settings));
}

@Override
public void testFieldHasValue() {
assertTrue(
Expand Down

0 comments on commit 93ca9ad

Please sign in to comment.