match_all filter with empty array (instead of obj) fires exception when used with facets

fixes #2493
This commit is contained in:
Shay Banon 2012-12-26 15:35:30 -08:00
parent 2a57e7cd4b
commit 8a17222ff2
5 changed files with 24 additions and 2 deletions

View File

@ -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;

View File

@ -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()) {

View File

@ -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();

View File

@ -0,0 +1,3 @@
{
"match_all": {}
}

View File

@ -0,0 +1,3 @@
{
"match_all": []
}