File tree Expand file tree Collapse file tree 7 files changed +45
-48
lines changed
server/src/main/java/org/elasticsearch
x-pack/plugin/inference/src
main/java/org/elasticsearch/xpack/inference
yamlRestTest/resources/rest-api-spec/test/inference Expand file tree Collapse file tree 7 files changed +45
-48
lines changed Original file line number Diff line number Diff line change 11pr : 121720
2- summary : Fix - Requesting `_inference_fields` when using legacy format causes shard
3- failure
4- area : Relevance
2+ summary : Skip fetching _inference_fields field in legacy semantic_text format
3+ area : Search
54type : bug
65issues : []
Original file line number Diff line number Diff line change @@ -801,7 +801,8 @@ public static boolean isMetadataFieldStatic(String fieldName) {
801801 * this method considers all mapper plugins
802802 */
803803 public boolean isMetadataField (String field ) {
804- return mapperRegistry .getMetadataMapperParsers (indexVersionCreated ).containsKey (field );
804+ var mapper = mappingLookup ().getMapper (field );
805+ return mapper instanceof MetadataFieldMapper ;
805806 }
806807
807808 /**
Original file line number Diff line number Diff line change @@ -71,7 +71,6 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) {
7171 .stream ()
7272 .filter (
7373 fieldAndFormat -> (searchExecutionContext .isMetadataField (fieldAndFormat .field ) == false
74- || searchExecutionContext .fieldExistsInIndex (fieldAndFormat .field ) == false
7574 || searchExecutionContext .getFieldType (fieldAndFormat .field ).isStored () == false
7675 || IdFieldMapper .NAME .equals (fieldAndFormat .field )
7776 || SourceFieldMapper .NAME .equals (fieldAndFormat .field ))
@@ -88,7 +87,6 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) {
8887 continue ;
8988 }
9089 if (searchExecutionContext .isMetadataField (fieldAndFormat .field )
91- && searchExecutionContext .fieldExistsInIndex (fieldAndFormat .field )
9290 && searchExecutionContext .getFieldType (fieldAndFormat .field ).isStored ()) {
9391 fetchContextMetadataFields .add (fieldAndFormat );
9492 }
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ public Set<NodeFeature> getTestFeatures() {
3636 SemanticTextFieldMapper .SEMANTIC_TEXT_DELETE_FIX ,
3737 SemanticTextFieldMapper .SEMANTIC_TEXT_ZERO_SIZE_FIX ,
3838 SemanticTextFieldMapper .SEMANTIC_TEXT_ALWAYS_EMIT_INFERENCE_ID_FIX ,
39+ SemanticTextFieldMapper .SEMANTIC_TEXT_SKIP_INFERENCE_FIELDS ,
3940 SEMANTIC_TEXT_HIGHLIGHTER ,
4041 SEMANTIC_MATCH_QUERY_REWRITE_INTERCEPTION_SUPPORTED ,
4142 SEMANTIC_SPARSE_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED ,
Original file line number Diff line number Diff line change @@ -117,6 +117,7 @@ public class SemanticTextFieldMapper extends FieldMapper implements InferenceFie
117117 public static final NodeFeature SEMANTIC_TEXT_ALWAYS_EMIT_INFERENCE_ID_FIX = new NodeFeature (
118118 "semantic_text.always_emit_inference_id_fix"
119119 );
120+ public static final NodeFeature SEMANTIC_TEXT_SKIP_INFERENCE_FIELDS = new NodeFeature ("semantic_text.skip_inference_fields" );
120121
121122 public static final String CONTENT_TYPE = "semantic_text" ;
122123 public static final String DEFAULT_ELSER_2_INFERENCE_ID = DEFAULT_ELSER_ID ;
Original file line number Diff line number Diff line change @@ -650,3 +650,42 @@ setup:
650650 - match : { hits.total.value: 1 }
651651 - match : { hits.total.relation: eq }
652652 - match : { hits.hits.0._source.dense_field.text: "updated text" }
653+
654+ ---
655+ " Skip fetching _inference_fields " :
656+ - requires :
657+ cluster_features : semantic_text.skip_inference_fields
658+ reason : Skip _inference_fields when search is performed on legacy semantic_text format.
659+
660+ - do :
661+ indices.create :
662+ index : test-skip-inference_field-index
663+ body :
664+ settings :
665+ index :
666+ mapping :
667+ semantic_text :
668+ use_legacy_format : true
669+ mappings :
670+ properties :
671+ inference_field :
672+ type : semantic_text
673+ inference_id : sparse-inference-id
674+
675+ - do :
676+ index :
677+ index : test-skip-inference_field-index
678+ id : doc_1
679+ body :
680+ inference_field : " test value"
681+ refresh : true
682+
683+ - do :
684+ search :
685+ index : test-skip-inference_field-index
686+ body :
687+ fields : [ _inference_fields ]
688+ query :
689+ match_all : { }
690+
691+ - not_exists : hits.hits.0._source._inference_fields
Original file line number Diff line number Diff line change @@ -1003,45 +1003,3 @@ setup:
10031003 - length : { aggregations.agg_ids.buckets: 1 }
10041004 - match : { aggregations.agg_ids.buckets.0.key: "doc_1" }
10051005 - match : { aggregations.agg_ids.buckets.0.doc_count: 1 }
1006-
1007- ---
1008- " Querying_inference_fields with semantic_text legacy format " :
1009- - do :
1010- indices.create :
1011- index : test-index
1012- body :
1013- settings :
1014- index :
1015- mapping :
1016- semantic_text :
1017- use_legacy_format : true
1018- mappings :
1019- properties :
1020- inference_field :
1021- type : semantic_text
1022- inference_id : sparse-inference-id
1023- source_field :
1024- type : text
1025- copy_to : inference_field
1026-
1027- - do :
1028- index :
1029- index : test-index
1030- id : doc_1
1031- body :
1032- inference_field : " test value"
1033- source_field : " source value"
1034- refresh : true
1035-
1036- - do :
1037- search :
1038- index : test-index
1039- body :
1040- fields : [ _inference_fields ]
1041- query :
1042- match_all : { }
1043-
1044- - match : { hits.total.value: 1 }
1045- - match : { hits.total.relation: eq }
1046- - match : { hits.hits.0._source.source_field: "source value" }
1047- - match : { hits.hits.0._source.inference_field.text: "test value" }
You can’t perform that action at this time.
0 commit comments