Skip to content

Commit

Permalink
match_all filter with empty array (instead of obj) fires exception wh…
Browse files Browse the repository at this point in the history
…en used with facets

fixes elastic#2493
  • Loading branch information
kimchy committed Dec 26, 2012
1 parent be09391 commit dc2cd0d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
Expand Up @@ -48,7 +48,7 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
XContentParser parser = parseContext.parser();

XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
while (((token = parser.nextToken()) != XContentParser.Token.END_OBJECT && token != XContentParser.Token.END_ARRAY)) {
}

return Queries.MATCH_ALL_FILTER;
Expand Down
Expand Up @@ -53,7 +53,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
String currentFieldName = null;

XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
while (((token = parser.nextToken()) != XContentParser.Token.END_OBJECT && token != XContentParser.Token.END_ARRAY)) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
Expand Down
Expand Up @@ -246,6 +246,22 @@ public void testMatchAll() throws Exception {
assertThat((double) matchAllDocsQuery.getBoost(), closeTo(1.2, 0.01));
}

@Test
public void testMatchAllEmpty1() throws Exception {
IndexQueryParserService queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/test/unit/index/query/match_all_empty1.json");
Query parsedQuery = queryParser.parse(query).query();
assertThat(parsedQuery, sameInstance(Queries.MATCH_ALL_QUERY));
}

@Test
public void testMatchAllEmpty2() throws Exception {
IndexQueryParserService queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/test/unit/index/query/match_all_empty2.json");
Query parsedQuery = queryParser.parse(query).query();
assertThat(parsedQuery, sameInstance(Queries.MATCH_ALL_QUERY));
}

@Test
public void testStarColonStar() throws Exception {
IndexQueryParserService queryParser = queryParser();
Expand Down
@@ -0,0 +1,3 @@
{
"match_all": {}
}
@@ -0,0 +1,3 @@
{
"match_all": []
}

0 comments on commit dc2cd0d

Please sign in to comment.