File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search
server/src/main/java/org/elasticsearch Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ setup:
4545 type : keyword
4646 text :
4747 type : text
48+ text_stored_not_indexed :
49+ type : text
50+ store : true
51+ index : false
4852
4953 - do :
5054 headers :
7074 inner1 : " foo"
7175 inner2 : " bar"
7276 text : " foo bar"
77+ text_stored_not_indexed : " foo bar"
7378
7479 - do :
7580 headers :
9499 object :
95100 inner1 : " foo"
96101 text : " foo bar"
102+ text_stored_not_indexed : " foo bar"
97103
98104 - do :
99105 headers :
@@ -119,6 +125,7 @@ setup:
119125 object :
120126 inner2 : " bar"
121127 text : " foo bar"
128+ text_stored_not_indexed : " foo bar"
122129
123130 - do :
124131 index :
@@ -1268,3 +1275,25 @@ setup:
12681275 field : text
12691276
12701277 - match : {hits.total: 1}
1278+
1279+ ---
1280+ " Test exists query on text field with no dv, that is stored but not indexed " :
1281+ - requires :
1282+ capabilities :
1283+ - method : POST
1284+ path : /_search
1285+ capabilities : [ field_exists_query_for_text_fields_no_index_or_dv ]
1286+ test_runner_features : capabilities
1287+ reason : " Before the fix, this query would throw an ISE because the field is not indexed and has no doc values."
1288+
1289+ - do :
1290+ search :
1291+ rest_total_hits_as_int : true
1292+ index : test
1293+ body :
1294+ query :
1295+ exists :
1296+ field : text_stored_not_indexed
1297+
1298+ # this should not throw, but rather return 0 hits, as the field is not indexed nor it has doc values
1299+ - match : {hits.total: 0}
Original file line number Diff line number Diff line change @@ -371,7 +371,7 @@ public Query regexpQuery(
371371 }
372372
373373 public Query existsQuery (SearchExecutionContext context ) {
374- if (hasDocValues () || getTextSearchInfo ().hasNorms ()) {
374+ if (hasDocValues () || ( isIndexed () && getTextSearchInfo ().hasNorms () )) {
375375 return new FieldExistsQuery (name ());
376376 } else {
377377 return new TermQuery (new Term (FieldNamesFieldMapper .NAME , name ()));
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ private SearchCapabilities() {}
5252 private static final String SIGNIFICANT_TERMS_ON_NESTED_FIELDS = "significant_terms_on_nested_fields" ;
5353 private static final String EXCLUDE_VECTORS_PARAM = "exclude_vectors_param" ;
5454 private static final String DENSE_VECTOR_UPDATABLE_BBQ = "dense_vector_updatable_bbq" ;
55+ private static final String FIELD_EXISTS_QUERY_FOR_TEXT_FIELDS_NO_INDEX_OR_DV = "field_exists_query_for_text_fields_no_index_or_dv" ;
5556
5657 public static final Set <String > CAPABILITIES ;
5758 static {
@@ -75,6 +76,7 @@ private SearchCapabilities() {}
7576 capabilities .add (SIGNIFICANT_TERMS_ON_NESTED_FIELDS );
7677 capabilities .add (EXCLUDE_VECTORS_PARAM );
7778 capabilities .add (DENSE_VECTOR_UPDATABLE_BBQ );
79+ capabilities .add (FIELD_EXISTS_QUERY_FOR_TEXT_FIELDS_NO_INDEX_OR_DV );
7880 CAPABILITIES = Set .copyOf (capabilities );
7981 }
8082}
You can’t perform that action at this time.
0 commit comments