From 8a17222ff201d64225dd6c97028e07754447249e Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Wed, 26 Dec 2012 15:35:30 -0800 Subject: [PATCH] match_all filter with empty array (instead of obj) fires exception when used with facets fixes #2493 --- .../index/query/MatchAllFilterParser.java | 2 +- .../index/query/MatchAllQueryParser.java | 2 +- .../index/query/SimpleIndexQueryParserTests.java | 16 ++++++++++++++++ .../test/unit/index/query/match_all_empty1.json | 3 +++ .../test/unit/index/query/match_all_empty2.json | 3 +++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/elasticsearch/test/unit/index/query/match_all_empty1.json create mode 100644 src/test/java/org/elasticsearch/test/unit/index/query/match_all_empty2.json 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