Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better exception if array passed to term query. #11384

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -89,6 +89,8 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
fieldName = currentFieldName;
value = parser.objectBytes();
}
} else if (token == XContentParser.Token.START_ARRAY) {
throw new QueryParsingException(parseContext, "[term] query does not support array of values");
}
}

Expand Down
Expand Up @@ -516,6 +516,13 @@ public void testTermQuery() throws IOException {
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;
Expand Down
@@ -0,0 +1,5 @@
{
"term": {
"age": [34, 35]
}
}