From 359f45988fa5550ff44a0f805fa050eb9a221405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Wed, 20 Apr 2016 13:19:12 +0200 Subject: Handle empty query bodies at parse time and remove EmptyQueryBuilder Currently we support empty query clauses like the filter in "constant_score" : { "filter" : { } } How these clauses are handled depends on the surrounding query. They later are either ignored, converted to match all or no documents or passed up further in the query hierarchy. During parsing these claues are currently represented as EmptyQueryBuilders. When not handled anywhere else, these special cases need to be checked for on the shard when building the lucene query. This is trappy, so this PR changes the parsing of compound queries. Instead of returning QueryBuilder, the core query parsing method QueryShardContext#parseInnerQueryBuilder() now return an Optional which can be empty in the case of empty query clauses. This has the advantage of forcing callers to deal with this sooner or later. When encountering empty Optionals, compound query builders now have the choice to ignore them, pass them on or rewrite to a different query, depending on context. --- .../java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java') diff --git a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index 66f623cbbb..5fa36ec977 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -805,7 +805,7 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException { XContentParser parser = parseContext.parser(); // document inputs @@ -955,7 +955,7 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder texts, List items) throws IOException { -- cgit v1.2.3