Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/121720.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 121720
summary: Skip fetching _inference_fields field in legacy semantic_text format
area: Search
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,8 @@ public static boolean isMetadataFieldStatic(String fieldName) {
* this method considers all mapper plugins
*/
public boolean isMetadataField(String field) {
return mapperRegistry.getMetadataMapperParsers(indexVersionCreated).containsKey(field);
var mapper = mappingLookup().getMapper(field);
return mapper instanceof MetadataFieldMapper;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.CheckedFunction;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.mapper.MapperService.MergeReason;
Expand All @@ -26,6 +29,7 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -304,16 +308,56 @@ public void testMappingRecoverySkipFieldNameLengthLimit() throws Throwable {

public void testIsMetadataField() throws IOException {
IndexVersion version = IndexVersionUtils.randomCompatibleVersion(random());
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build();

MapperService mapperService = createMapperService(settings, mapping(b -> {}));
assertFalse(mapperService.isMetadataField(randomAlphaOfLengthBetween(10, 15)));
CheckedFunction<IndexMode, MapperService, IOException> initMapperService = (indexMode) -> {
Settings.Builder settingsBuilder = Settings.builder()
.put(IndexMetadata.SETTING_VERSION_CREATED, version)
.put(IndexSettings.MODE.getKey(), indexMode);

for (String builtIn : IndicesModule.getBuiltInMetadataFields()) {
if (NestedPathFieldMapper.NAME.equals(builtIn) && version.before(IndexVersions.V_8_0_0)) {
continue; // Nested field does not exist in the 7x line
if (indexMode == IndexMode.TIME_SERIES) {
settingsBuilder.put(IndexMetadata.INDEX_ROUTING_PATH.getKey(), "foo");
}
assertTrue("Expected " + builtIn + " to be a metadata field for version " + version, mapperService.isMetadataField(builtIn));

return createMapperService(settingsBuilder.build(), mapping(b -> {}));
};

Consumer<MapperService> assertMapperService = (mapperService) -> {
assertFalse(mapperService.isMetadataField(randomAlphaOfLengthBetween(10, 15)));

for (String builtIn : IndicesModule.getBuiltInMetadataFields()) {
if (NestedPathFieldMapper.NAME.equals(builtIn) && version.before(IndexVersions.V_8_0_0)) {
continue; // Nested field does not exist in the 7x line
}
boolean isTimeSeriesField = builtIn.equals("_tsid") || builtIn.equals("_ts_routing_hash");
boolean isTimeSeriesMode = mapperService.getIndexSettings().getMode().equals(IndexMode.TIME_SERIES);

if (isTimeSeriesField && isTimeSeriesMode == false) {
assertFalse(
"Expected "
+ builtIn
+ " to not be a metadata field for version "
+ version
+ " and index mode "
+ mapperService.getIndexSettings().getMode(),
mapperService.isMetadataField(builtIn)
);
} else {
assertTrue(
"Expected "
+ builtIn
+ " to be a metadata field for version "
+ version
+ " and index mode "
+ mapperService.getIndexSettings().getMode(),
mapperService.isMetadataField(builtIn)
);
}
}
};

for (IndexMode indexMode : IndexMode.values()) {
MapperService mapperService = initMapperService.apply(indexMode);
assertMapperService.accept(mapperService);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public Set<NodeFeature> getTestFeatures() {
SemanticTextFieldMapper.SEMANTIC_TEXT_DELETE_FIX,
SemanticTextFieldMapper.SEMANTIC_TEXT_ZERO_SIZE_FIX,
SemanticTextFieldMapper.SEMANTIC_TEXT_ALWAYS_EMIT_INFERENCE_ID_FIX,
SemanticTextFieldMapper.SEMANTIC_TEXT_SKIP_INFERENCE_FIELDS,
SEMANTIC_TEXT_HIGHLIGHTER,
SEMANTIC_MATCH_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
SEMANTIC_SPARSE_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public class SemanticTextFieldMapper extends FieldMapper implements InferenceFie
public static final NodeFeature SEMANTIC_TEXT_ALWAYS_EMIT_INFERENCE_ID_FIX = new NodeFeature(
"semantic_text.always_emit_inference_id_fix"
);
public static final NodeFeature SEMANTIC_TEXT_SKIP_INFERENCE_FIELDS = new NodeFeature("semantic_text.skip_inference_fields");

public static final String CONTENT_TYPE = "semantic_text";
public static final String DEFAULT_ELSER_2_INFERENCE_ID = DEFAULT_ELSER_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,28 @@ setup:
- match: { hits.total.value: 1 }
- match: { hits.total.relation: eq }
- match: { hits.hits.0._source.dense_field.text: "updated text" }

---
"Skip fetching _inference_fields":
- requires:
cluster_features: semantic_text.skip_inference_fields
reason: Skip _inference_fields when search is performed on legacy semantic_text format.

- do:
index:
index: test-index
id: doc_1
body:
sparse_field: "test value"
refresh: true

- do:
search:
index: test-index
body:
fields: [ _inference_fields ]
query:
match_all: { }

- match: { hits.total.value: 1 }
- not_exists: hits.hits.0._source._inference_fields