summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
diff options
context:
space:
mode:
authorChristoph Büscher <christoph@elastic.co>2016-04-20 13:19:12 +0200
committerChristoph Büscher <christoph@elastic.co>2016-06-02 11:25:56 +0200
commit359f45988fa5550ff44a0f805fa050eb9a221405 (patch)
tree6facefbd87f2ed55d9f2142b7896d6f65796bf05 /core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
parentb2724c0d08267486efc261a30bdb686cb9977f5d (diff)
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.
Diffstat (limited to 'core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java')
-rw-r--r--core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java4
1 files changed, 2 insertions, 2 deletions
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<MoreLikeThisQ
builder.endObject();
}
- public static MoreLikeThisQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
+ public static Optional<MoreLikeThisQueryBuilder> fromXContent(QueryParseContext parseContext) throws IOException {
XContentParser parser = parseContext.parser();
// document inputs
@@ -955,7 +955,7 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
if (stopWords != null) {
moreLikeThisQueryBuilder.stopWords(stopWords);
}
- return moreLikeThisQueryBuilder;
+ return Optional.of(moreLikeThisQueryBuilder);
}
private static void parseLikeField(QueryParseContext parseContext, List<String> texts, List<Item> items) throws IOException {