Skip to content

Commit 7d05df9

Browse files
committed
updating test
1 parent 6338b59 commit 7d05df9

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search/160_exists_query.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ setup:
191191
doc_values: false
192192
text:
193193
type: text
194+
keyword_stored_norms_not_indexed:
195+
type: keyword
196+
doc_values: false
197+
index: false
198+
store: true
199+
norms: true
194200

195201
- do:
196202
headers:
@@ -216,6 +222,7 @@ setup:
216222
inner1: "foo"
217223
inner2: "bar"
218224
text: "foo bar"
225+
keyword_stored_norms_not_indexed: "foo bar"
219226

220227
- do:
221228
headers:
@@ -240,6 +247,7 @@ setup:
240247
object:
241248
inner1: "foo"
242249
text: "foo bar"
250+
keyword_stored_norms_not_indexed: "foo bar"
243251

244252
- do:
245253
headers:
@@ -265,6 +273,7 @@ setup:
265273
object:
266274
inner2: "bar"
267275
text: "foo bar"
276+
keyword_stored_norms_not_indexed: "foo bar"
268277

269278
- do:
270279
index:
@@ -1297,3 +1306,26 @@ setup:
12971306

12981307
# this should not throw, but rather return 0 hits, as the field is not indexed nor it has doc values
12991308
- match: {hits.total: 0}
1309+
1310+
1311+
---
1312+
"Test exists query on keyword field with no dv, that is stored, with norms, but not indexed":
1313+
- requires:
1314+
capabilities:
1315+
- method: POST
1316+
path: /_search
1317+
capabilities: [ field_exists_query_for_text_fields_no_index_or_dv ]
1318+
test_runner_features: capabilities
1319+
reason: "Before the fix, this query would throw an ISE because the field is not indexed and has no doc values."
1320+
1321+
- do:
1322+
search:
1323+
rest_total_hits_as_int: true
1324+
index: test-no-dv
1325+
body:
1326+
query:
1327+
exists:
1328+
field: keyword_stored_norms_not_indexed
1329+
1330+
# this should not throw, but rather return 0 hits, as the field is not indexed nor it has doc values
1331+
- match: {hits.total: 0}

server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldTypeTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ public void testExistsQuery() {
137137
FieldType fieldType = new FieldType();
138138
fieldType.setOmitNorms(false);
139139
KeywordFieldType ft = new KeywordFieldType("field", fieldType);
140-
assertEquals(new FieldExistsQuery("field"), ft.existsQuery(MOCK_CONTEXT));
140+
// updated in #130531 so that a field that is neither indexed nor has doc values will generate a TermQuery
141+
// to avoid ISE from FieldExistsQuery
142+
assertEquals(new TermQuery(new Term(FieldNamesFieldMapper.NAME, "field")), ft.existsQuery(MOCK_CONTEXT));
141143
}
142144
{
143145
KeywordFieldType ft = new KeywordFieldType("field", true, false, Collections.emptyMap());

0 commit comments

Comments
 (0)