Query DSL: throw an exception if array passed to `term` query.

Closes #11246
Closes #11384
This commit is contained in:
Spyros Kapnissis 2015-05-27 09:43:33 +03:00 committed by Luca Cavanna
parent a7779d8e1d
commit 784a26321b
3 changed files with 14 additions and 0 deletions

View File

@ -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");
}
}

View File

@ -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;

View File

@ -0,0 +1,5 @@
{
"term": {
"age": [34, 35]
}
}