diff --git a/src/main/java/org/elasticsearch/index/query/TermQueryParser.java b/src/main/java/org/elasticsearch/index/query/TermQueryParser.java index 5e6babdbaeb..c0755289f06 100644 --- a/src/main/java/org/elasticsearch/index/query/TermQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/TermQueryParser.java @@ -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"); } } diff --git a/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java b/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java index 992f1777a2c..88c3b9d2f90 100644 --- a/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java +++ b/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java @@ -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; diff --git a/src/test/java/org/elasticsearch/index/query/term-array-invalid.json b/src/test/java/org/elasticsearch/index/query/term-array-invalid.json new file mode 100644 index 00000000000..a198bc2dafc --- /dev/null +++ b/src/test/java/org/elasticsearch/index/query/term-array-invalid.json @@ -0,0 +1,5 @@ +{ + "term": { + "age": [34, 35] + } +}