diff --git a/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java b/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java index e0edf1eec74..a5c16471b98 100644 --- a/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java +++ b/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.query; import com.google.common.collect.ImmutableMap; +import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.apache.lucene.util.CloseableThreadLocal; import org.elasticsearch.ElasticSearchException; @@ -261,7 +262,11 @@ public class IndexQueryParserService extends AbstractIndexComponent { public ParsedFilter parseInnerFilter(XContentParser parser) throws IOException { QueryParseContext context = cache.get(); context.reset(parser); - return new ParsedFilter(context.parseInnerFilter(), context.copyNamedFilters()); + Filter filter = context.parseInnerFilter(); + if (filter == null) { + return null; + } + return new ParsedFilter(filter, context.copyNamedFilters()); } @Nullable diff --git a/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java b/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java index 05b661f8b3e..14d04540013 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java @@ -1231,6 +1231,13 @@ public class SimpleQueryTests extends AbstractSharedClusterTest { assertThat(response.getHits().totalHits(), equalTo(2l)); } + @Test + public void testEmptyTopLevelFilter() { + client().prepareIndex("test", "type", "1").setSource("field", "value").setRefresh(true).execute().actionGet(); + SearchResponse searchResponse = client().prepareSearch().setFilter("{}").execute().actionGet(); + assertNoFailures(searchResponse); + } + @Test // see #2926 public void testMustNot() throws ElasticSearchException, IOException { client().admin().indices().prepareDelete().execute().actionGet();