diff --git a/src/main/java/org/elasticsearch/index/query/MatchAllFilterParser.java b/src/main/java/org/elasticsearch/index/query/MatchAllFilterParser.java index bafb81489af..8da390840ca 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchAllFilterParser.java +++ b/src/main/java/org/elasticsearch/index/query/MatchAllFilterParser.java @@ -48,7 +48,7 @@ public class MatchAllFilterParser implements FilterParser { 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; diff --git a/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java b/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java index 6ce238c51c4..9d2cfb48c46 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java @@ -53,7 +53,7 @@ public class MatchAllQueryParser implements QueryParser { 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()) { diff --git a/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java b/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java index c22370aad90..2bcd06c39ca 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java @@ -259,6 +259,22 @@ public class SimpleIndexQueryParserTests { 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(); diff --git a/src/test/java/org/elasticsearch/test/unit/index/query/match_all_empty1.json b/src/test/java/org/elasticsearch/test/unit/index/query/match_all_empty1.json new file mode 100644 index 00000000000..6dd141fe862 --- /dev/null +++ b/src/test/java/org/elasticsearch/test/unit/index/query/match_all_empty1.json @@ -0,0 +1,3 @@ +{ + "match_all": {} +} \ No newline at end of file diff --git a/src/test/java/org/elasticsearch/test/unit/index/query/match_all_empty2.json b/src/test/java/org/elasticsearch/test/unit/index/query/match_all_empty2.json new file mode 100644 index 00000000000..a0549df7130 --- /dev/null +++ b/src/test/java/org/elasticsearch/test/unit/index/query/match_all_empty2.json @@ -0,0 +1,3 @@ +{ + "match_all": [] +} \ No newline at end of file