Query DSL: throw an exception if array passed to `term` query.
Closes #11246 Closes #11384
This commit is contained in:
parent
a7779d8e1d
commit
784a26321b
|
@ -89,6 +89,8 @@ public class TermQueryParser implements QueryParser {
|
|||
fieldName = currentFieldName;
|
||||
value = parser.objectBytes();
|
||||
}
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
throw new QueryParsingException(parseContext, "[term] query does not support array of values");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -516,6 +516,13 @@ public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
|
|||
assertThat(fieldQuery.getTerm().bytes(), equalTo(indexedValueForSearch(34l)));
|
||||
}
|
||||
|
||||
@Test(expected = QueryParsingException.class)
|
||||
public void testTermQueryArrayInvalid() throws IOException {
|
||||
IndexQueryParserService queryParser = queryParser();
|
||||
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/term-array-invalid.json");
|
||||
unwrapTermQuery(queryParser.parse(query).query());
|
||||
}
|
||||
|
||||
private static TermQuery unwrapTermQuery(Query q) {
|
||||
assertThat(q, instanceOf(TermQuery.class));
|
||||
return (TermQuery) q;
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"term": {
|
||||
"age": [34, 35]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue