From 2fd3e7922491e635f24fd3bb309c7071d783b1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Mon, 13 Apr 2015 18:50:03 +0200 Subject: [PATCH] Query refactoring: Introduce toQuery() and fromXContent() in QueryBuilders and QueryParsers The planed refactoring of search queries layed out in #9901 requires to split the "parse()" method in QueryParsers into two methods, first a "fromXContent(...)" method that allows parsing to an intermediate query representation (currently called FooQueryBuilder) and second a "Query toQuery(...)" method on these intermediate representations that create the actual lucene queries. This PR is a first step in that direction as it introduces the interface changes necessary for the further refactoring. It introduces the new interface methods while for now keeping the old Builder/Parsers still in place by delegating the new "toQuery()" implementations to the existing "parse()" methods, and by introducing a "catch-all" "fromXContent()" implementation in a BaseQueryParser that returns a temporary QueryBuilder wrapper implementation. This allows us to refactor the existing QueryBuilders step by step while already beeing able to start refactoring queries with nested inner queries. Closes #10580 --- .../index/query/BaseQueryBuilder.java | 10 ++++ .../index/query/BaseQueryParser.java | 37 +++++++++++++ .../index/query/BaseQueryParserTemp.java | 37 +++++++++++++ .../index/query/BoolQueryBuilder.java | 7 ++- .../index/query/BoolQueryParser.java | 4 +- .../index/query/BoostingQueryBuilder.java | 4 ++ .../index/query/BoostingQueryParser.java | 2 +- .../index/query/CommonTermsQueryBuilder.java | 7 +++ .../index/query/CommonTermsQueryParser.java | 2 +- .../query/ConstantScoreQueryBuilder.java | 15 ++++-- .../index/query/ConstantScoreQueryParser.java | 4 +- .../index/query/DisMaxQueryBuilder.java | 7 ++- .../index/query/DisMaxQueryParser.java | 4 +- .../query/FieldMaskingSpanQueryBuilder.java | 4 ++ .../query/FieldMaskingSpanQueryParser.java | 4 +- .../index/query/FilteredQueryBuilder.java | 4 ++ .../index/query/FilteredQueryParser.java | 2 +- .../index/query/FuzzyQueryBuilder.java | 10 ++-- .../index/query/FuzzyQueryParser.java | 2 +- .../index/query/GeoShapeQueryBuilder.java | 3 ++ .../index/query/GeoShapeQueryParser.java | 6 +-- .../index/query/HasChildQueryBuilder.java | 4 ++ .../index/query/HasChildQueryParser.java | 2 +- .../index/query/HasParentQueryBuilder.java | 4 ++ .../index/query/HasParentQueryParser.java | 4 +- .../index/query/IdsQueryBuilder.java | 6 ++- .../index/query/IdsQueryParser.java | 3 +- .../index/query/IndicesQueryBuilder.java | 6 ++- .../index/query/IndicesQueryParser.java | 2 +- .../index/query/MatchAllQueryBuilder.java | 4 ++ .../index/query/MatchAllQueryParser.java | 2 +- .../index/query/MatchQueryBuilder.java | 6 ++- .../index/query/MatchQueryParser.java | 2 +- .../index/query/MoreLikeThisQueryBuilder.java | 10 +++- .../index/query/MoreLikeThisQueryParser.java | 5 +- .../index/query/MultiMatchQueryBuilder.java | 4 ++ .../index/query/MultiMatchQueryParser.java | 3 +- .../index/query/NestedQueryBuilder.java | 3 ++ .../index/query/NestedQueryParser.java | 2 +- .../index/query/PrefixQueryBuilder.java | 6 ++- .../index/query/PrefixQueryParser.java | 4 +- .../index/query/QueryBuilder.java | 15 +++++- .../index/query/QueryParseContext.java | 47 ++++++++++++---- .../index/query/QueryParser.java | 22 ++++++-- .../index/query/QueryStringQueryBuilder.java | 4 ++ .../index/query/QueryStringQueryParser.java | 2 +- .../query/QueryWrappingQueryBuilder.java | 53 +++++++++++++++++++ .../index/query/RangeQueryBuilder.java | 6 +++ .../index/query/RangeQueryParser.java | 2 +- .../index/query/RegexpQueryBuilder.java | 5 ++ .../index/query/RegexpQueryParser.java | 2 +- .../index/query/SimpleQueryStringBuilder.java | 5 ++ .../index/query/SimpleQueryStringParser.java | 2 +- .../index/query/SpanFirstQueryBuilder.java | 5 ++ .../index/query/SpanFirstQueryParser.java | 4 +- .../query/SpanMultiTermQueryBuilder.java | 4 ++ .../index/query/SpanMultiTermQueryParser.java | 2 +- .../index/query/SpanNearQueryBuilder.java | 5 ++ .../index/query/SpanNearQueryParser.java | 2 +- .../index/query/SpanNotQueryBuilder.java | 5 ++ .../index/query/SpanNotQueryParser.java | 4 +- .../index/query/SpanOrQueryBuilder.java | 5 ++ .../index/query/SpanOrQueryParser.java | 4 +- .../index/query/SpanTermQueryBuilder.java | 7 ++- .../index/query/SpanTermQueryParser.java | 4 +- .../index/query/TemplateQueryBuilder.java | 5 ++ .../index/query/TemplateQueryParser.java | 2 +- .../index/query/TermQueryBuilder.java | 5 ++ .../index/query/TermQueryParser.java | 2 +- .../index/query/TermsQueryBuilder.java | 5 ++ .../index/query/TermsQueryParser.java | 2 +- .../index/query/TopChildrenQueryBuilder.java | 5 ++ .../index/query/TopChildrenQueryParser.java | 2 +- .../index/query/WildcardQueryBuilder.java | 7 ++- .../index/query/WildcardQueryParser.java | 4 +- .../index/query/WrapperQueryBuilder.java | 6 +++ .../index/query/WrapperQueryParser.java | 2 +- .../FunctionScoreQueryBuilder.java | 8 ++- .../FunctionScoreQueryParser.java | 11 +++- .../index/query/guice/MyJsonQueryParser.java | 8 +++ .../query/plugin/PluginJsonQueryParser.java | 8 +++ 81 files changed, 471 insertions(+), 84 deletions(-) create mode 100644 src/main/java/org/elasticsearch/index/query/BaseQueryParser.java create mode 100644 src/main/java/org/elasticsearch/index/query/BaseQueryParserTemp.java create mode 100644 src/main/java/org/elasticsearch/index/query/QueryWrappingQueryBuilder.java diff --git a/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java index 6cb131507407f..1c7c6ebcf33c2 100644 --- a/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.apache.lucene.search.Query; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -68,5 +69,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } + public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException { + return parseContext.indexQueryParserService().queryParser(parserName()).parse(parseContext); + } + + /** + * @return the name of the parser class the default toQuery() method delegates to + */ + protected abstract String parserName(); + protected abstract void doXContent(XContentBuilder builder, Params params) throws IOException; } diff --git a/src/main/java/org/elasticsearch/index/query/BaseQueryParser.java b/src/main/java/org/elasticsearch/index/query/BaseQueryParser.java new file mode 100644 index 0000000000000..e42f022683a67 --- /dev/null +++ b/src/main/java/org/elasticsearch/index/query/BaseQueryParser.java @@ -0,0 +1,37 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.query; + +import org.apache.lucene.search.Query; + +import java.io.IOException; + +/** + * Class used during the query parsers refactoring. + * All query parsers that have a refactored "fromXContent" method can be changed to extend this instead of {@link BaseQueryParserTemp}. + * Keeps old {@link QueryParser#parse(QueryParseContext)} method as a stub delegating to + * {@link QueryParser#fromXContent(QueryParseContext)} and {@link QueryBuilder#toQuery(QueryParseContext)}} + */ +public abstract class BaseQueryParser implements QueryParser { + + public final Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { + return fromXContent(parseContext).toQuery(parseContext); + } +} diff --git a/src/main/java/org/elasticsearch/index/query/BaseQueryParserTemp.java b/src/main/java/org/elasticsearch/index/query/BaseQueryParserTemp.java new file mode 100644 index 0000000000000..4067a41137e4b --- /dev/null +++ b/src/main/java/org/elasticsearch/index/query/BaseQueryParserTemp.java @@ -0,0 +1,37 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.query; + +import org.apache.lucene.search.Query; + +import java.io.IOException; + +/** + * This class with method impl is an intermediate step in the refactoring. + * Method should be should be overwritten for all queries that already implement the toQuery/fromXContent split correctly. + * To be removed once all queries are refactored. + */ +public abstract class BaseQueryParserTemp implements QueryParser { + + public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException { + Query query = parse(parseContext); + return new QueryWrappingQueryBuilder(query); + } +} diff --git a/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java index ca12ff5a92751..53b07f880939d 100644 --- a/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java @@ -42,7 +42,7 @@ public class BoolQueryBuilder extends BaseQueryBuilder implements BoostableQuery private Boolean disableCoord; private String minimumShouldMatch; - + private Boolean adjustPureNegative; private String queryName; @@ -126,7 +126,7 @@ public BoolQueryBuilder minimumShouldMatch(String minimumShouldMatch) { public boolean hasClauses() { return !(mustClauses.isEmpty() && shouldClauses.isEmpty() && mustNotClauses.isEmpty()); } - + /** * If a boolean query contains only negative ("must not") clauses should the * BooleanQuery be enhanced with a {@link MatchAllDocsQuery} in order to act @@ -185,4 +185,7 @@ private void doXArrayContent(String field, List clauses, XContentB } } + final protected String parserName() { + return BoolQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/BoolQueryParser.java b/src/main/java/org/elasticsearch/index/query/BoolQueryParser.java index 29d4ba2edd5b3..b9eaf1f1ae20d 100644 --- a/src/main/java/org/elasticsearch/index/query/BoolQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/BoolQueryParser.java @@ -37,7 +37,7 @@ /** * */ -public class BoolQueryParser implements QueryParser { +public class BoolQueryParser extends BaseQueryParserTemp { public static final String NAME = "bool"; @@ -62,7 +62,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars List clauses = newArrayList(); boolean adjustPureNegative = true; String queryName = null; - + String currentFieldName = null; XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { diff --git a/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java index aaf369155776d..1cfddcf11e395 100644 --- a/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java @@ -95,4 +95,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + final protected String parserName() { + return BoostingQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/BoostingQueryParser.java b/src/main/java/org/elasticsearch/index/query/BoostingQueryParser.java index a117256ece1a4..6747c139b8f7a 100644 --- a/src/main/java/org/elasticsearch/index/query/BoostingQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/BoostingQueryParser.java @@ -29,7 +29,7 @@ /** * */ -public class BoostingQueryParser implements QueryParser { +public class BoostingQueryParser extends BaseQueryParserTemp { public static final String NAME = "boosting"; diff --git a/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java index 16cb0bf7e57ec..523ed5636becf 100644 --- a/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java @@ -19,6 +19,9 @@ package org.elasticsearch.index.query; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.similarities.Similarity; import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -198,4 +201,8 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio builder.endObject(); builder.endObject(); } + + final protected String parserName() { + return CommonTermsQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/CommonTermsQueryParser.java b/src/main/java/org/elasticsearch/index/query/CommonTermsQueryParser.java index 46997ffb7fd3d..daef53cc279d2 100644 --- a/src/main/java/org/elasticsearch/index/query/CommonTermsQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/CommonTermsQueryParser.java @@ -39,7 +39,7 @@ /** * */ -public class CommonTermsQueryParser implements QueryParser { +public class CommonTermsQueryParser extends BaseQueryParserTemp { public static final String NAME = "common"; diff --git a/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java index ac85e61fb98e2..a31d271f759cc 100644 --- a/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.apache.lucene.search.Query; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -35,7 +36,7 @@ public class ConstantScoreQueryBuilder extends BaseQueryBuilder implements Boost private final QueryBuilder queryBuilder; private float boost = -1; - + /** * A query that wraps a filter and simply returns a constant score equal to the @@ -56,7 +57,7 @@ public ConstantScoreQueryBuilder(FilterBuilder filterBuilder) { public ConstantScoreQueryBuilder(QueryBuilder queryBuilder) { this.filterBuilder = null; this.queryBuilder = queryBuilder; - } + } /** * Sets the boost for this query. Documents matching this query will (in addition to the normal @@ -77,12 +78,16 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep queryBuilder.toXContent(builder, params); } else { builder.field("filter"); - filterBuilder.toXContent(builder, params); + filterBuilder.toXContent(builder, params); } - + if (boost != -1) { builder.field("boost", boost); } builder.endObject(); } -} \ No newline at end of file + + final protected String parserName() { + return ConstantScoreQueryParser.NAME; + } +} diff --git a/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryParser.java b/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryParser.java index 8c4c2dc261ec9..95ce1e7fa40e5 100644 --- a/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryParser.java @@ -33,7 +33,7 @@ /** * */ -public class ConstantScoreQueryParser implements QueryParser { +public class ConstantScoreQueryParser extends BaseQueryParserTemp { public static final String NAME = "constant_score"; @@ -108,4 +108,4 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars query.setBoost(boost); return query; } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java index 3be2370e0814b..c7f0c1b49db39 100644 --- a/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.apache.lucene.search.Query; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -99,4 +100,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.endArray(); builder.endObject(); } -} \ No newline at end of file + + final protected String parserName() { + return DisMaxQueryParser.NAME; + } +} diff --git a/src/main/java/org/elasticsearch/index/query/DisMaxQueryParser.java b/src/main/java/org/elasticsearch/index/query/DisMaxQueryParser.java index 82feb9854a5d9..ee114689d4cad 100644 --- a/src/main/java/org/elasticsearch/index/query/DisMaxQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/DisMaxQueryParser.java @@ -33,7 +33,7 @@ /** * */ -public class DisMaxQueryParser implements QueryParser { +public class DisMaxQueryParser extends BaseQueryParserTemp { public static final String NAME = "dis_max"; @@ -113,4 +113,4 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java index 3c397b78f1b52..ff9edc051ba40 100644 --- a/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java @@ -70,4 +70,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + final protected String parserName() { + return FieldMaskingSpanQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryParser.java b/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryParser.java index 2b69cf615610c..963e504e791a5 100644 --- a/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryParser.java @@ -32,7 +32,7 @@ /** * */ -public class FieldMaskingSpanQueryParser implements QueryParser { +public class FieldMaskingSpanQueryParser extends BaseQueryParserTemp { public static final String NAME = "field_masking_span"; @@ -101,4 +101,4 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java index 400a185016776..6bdd46500ff71 100644 --- a/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java @@ -85,4 +85,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + final protected String parserName() { + return FilteredQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java b/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java index 562c8e58ae9f7..71ae7a05cdde9 100644 --- a/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java @@ -41,7 +41,7 @@ /** * */ -public class FilteredQueryParser implements QueryParser { +public class FilteredQueryParser extends BaseQueryParserTemp { public static final String NAME = "filtered"; diff --git a/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java index 18cf2d0d22f7f..9d7179c19cd78 100644 --- a/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java @@ -42,7 +42,7 @@ public class FuzzyQueryBuilder extends BaseQueryBuilder implements MultiTermQuer private Integer prefixLength; private Integer maxExpansions; - + //LUCENE 4 UPGRADE we need a testcase for this + documentation private Boolean transpositions; @@ -83,7 +83,7 @@ public FuzzyQueryBuilder maxExpansions(int maxExpansions) { this.maxExpansions = maxExpansions; return this; } - + public FuzzyQueryBuilder transpositions(boolean transpositions) { this.transpositions = transpositions; return this; @@ -127,4 +127,8 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio } builder.endObject(); } -} \ No newline at end of file + + final protected String parserName() { + return FuzzyQueryParser.NAME; + } +} diff --git a/src/main/java/org/elasticsearch/index/query/FuzzyQueryParser.java b/src/main/java/org/elasticsearch/index/query/FuzzyQueryParser.java index 243f86534cdc8..5fcf35afb0a62 100644 --- a/src/main/java/org/elasticsearch/index/query/FuzzyQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/FuzzyQueryParser.java @@ -35,7 +35,7 @@ /** * */ -public class FuzzyQueryParser implements QueryParser { +public class FuzzyQueryParser extends BaseQueryParserTemp { public static final String NAME = "fuzzy"; private static final Fuzziness DEFAULT_FUZZINESS = Fuzziness.AUTO; diff --git a/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java index efda63bd3559b..b3877219f27eb 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java @@ -164,4 +164,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.endObject(); } + final protected String parserName() { + return GeoShapeQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/GeoShapeQueryParser.java b/src/main/java/org/elasticsearch/index/query/GeoShapeQueryParser.java index a7190443ed740..ce4c9d882deb2 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoShapeQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/GeoShapeQueryParser.java @@ -42,7 +42,7 @@ import java.io.IOException; -public class GeoShapeQueryParser implements QueryParser { +public class GeoShapeQueryParser extends BaseQueryParserTemp { public static final String NAME = "geo_shape"; @@ -181,7 +181,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars public void setFetchService(@Nullable ShapeFetchService fetchService) { this.fetchService = fetchService; } - + public static SpatialArgs getArgs(ShapeBuilder shape, ShapeRelation relation) { switch(relation) { case DISJOINT: @@ -192,7 +192,7 @@ public static SpatialArgs getArgs(ShapeBuilder shape, ShapeRelation relation) { return new SpatialArgs(SpatialOperation.IsWithin, shape.build()); default: throw new ElasticsearchIllegalArgumentException(""); - + } } } diff --git a/src/main/java/org/elasticsearch/index/query/HasChildQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/HasChildQueryBuilder.java index eec068a71017f..2dc00bb893039 100644 --- a/src/main/java/org/elasticsearch/index/query/HasChildQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/HasChildQueryBuilder.java @@ -141,4 +141,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + final protected String parserName() { + return HasChildQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java b/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java index c7e8f2567d41e..217aa7b134ba7 100644 --- a/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java @@ -47,7 +47,7 @@ /** * */ -public class HasChildQueryParser implements QueryParser { +public class HasChildQueryParser extends BaseQueryParserTemp { public static final String NAME = "has_child"; diff --git a/src/main/java/org/elasticsearch/index/query/HasParentQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/HasParentQueryBuilder.java index fbdc4f34a7af2..487c43be7e02d 100644 --- a/src/main/java/org/elasticsearch/index/query/HasParentQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/HasParentQueryBuilder.java @@ -96,5 +96,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + final protected String parserName() { + return HasParentQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java b/src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java index a44d5a699177f..964c798d15f41 100644 --- a/src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java @@ -45,7 +45,7 @@ import static org.elasticsearch.index.query.QueryParserUtils.ensureNotDeleteByQuery; -public class HasParentQueryParser implements QueryParser { +public class HasParentQueryParser extends BaseQueryParserTemp { public static final String NAME = "has_parent"; @@ -205,4 +205,4 @@ static Query createParentQuery(Query innerQuery, String parentType, boolean scor } } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java index d926fa504fe34..a9d575540bed9 100644 --- a/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java @@ -103,4 +103,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } -} \ No newline at end of file + + final protected String parserName() { + return IdsQueryParser.NAME; + } +} diff --git a/src/main/java/org/elasticsearch/index/query/IdsQueryParser.java b/src/main/java/org/elasticsearch/index/query/IdsQueryParser.java index fc8f2b7103abb..d7db7161fd706 100644 --- a/src/main/java/org/elasticsearch/index/query/IdsQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/IdsQueryParser.java @@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; + import org.apache.lucene.queries.TermsFilter; import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.Query; @@ -39,7 +40,7 @@ /** * */ -public class IdsQueryParser implements QueryParser { +public class IdsQueryParser extends BaseQueryParserTemp { public static final String NAME = "ids"; diff --git a/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java index 5b1434a0f6ce0..83ab18aab4975 100644 --- a/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java @@ -84,4 +84,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } -} \ No newline at end of file + + final protected String parserName() { + return IndicesQueryParser.NAME; + } +} diff --git a/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java b/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java index d5b5cefa149cf..92b1a43843b37 100644 --- a/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java @@ -35,7 +35,7 @@ /** */ -public class IndicesQueryParser implements QueryParser { +public class IndicesQueryParser extends BaseQueryParserTemp { public static final String NAME = "indices"; diff --git a/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java index 78a91a7fb73a8..206d4c870955c 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java @@ -50,4 +50,8 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio } builder.endObject(); } + + final protected String parserName() { + return MatchAllQueryParser.NAME; + } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java b/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java index 2017b94092172..c629acfbb83ed 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java @@ -31,7 +31,7 @@ /** * */ -public class MatchAllQueryParser implements QueryParser { +public class MatchAllQueryParser extends BaseQueryParserTemp { public static final String NAME = "match_all"; diff --git a/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java index 1f90999d525b6..82028876f6cf4 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java @@ -276,4 +276,8 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio builder.endObject(); builder.endObject(); } -} \ No newline at end of file + + final protected String parserName() { + return MatchQueryParser.NAME; + } +} diff --git a/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java b/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java index a0f595a662617..4d5f6a45e4158 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java @@ -35,7 +35,7 @@ /** * */ -public class MatchQueryParser implements QueryParser { +public class MatchQueryParser extends BaseQueryParserTemp { public static final String NAME = "match"; diff --git a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index ea814e6a15f5d..eba139f16907b 100644 --- a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -24,7 +24,11 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.lucene.uid.Versions; -import org.elasticsearch.common.xcontent.*; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.VersionType; import org.elasticsearch.search.fetch.source.FetchSourceContext; @@ -438,4 +442,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + final protected String parserName() { + return MoreLikeThisQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java index 1a065d1d90941..979ad9910a93b 100644 --- a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; + import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.queries.TermsFilter; import org.apache.lucene.search.BooleanClause; @@ -53,7 +54,7 @@ /** * */ -public class MoreLikeThisQueryParser implements QueryParser { +public class MoreLikeThisQueryParser extends BaseQueryParserTemp { public static final String NAME = "mlt"; private MoreLikeThisFetchService fetchService = null; @@ -355,4 +356,4 @@ private void handleExclude(BooleanQuery boolQuery, MultiTermVectorsRequest likeI boolQuery.add(query, BooleanClause.Occur.MUST_NOT); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java index e7bb3d7d215bc..be6e92f5a633c 100644 --- a/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java @@ -21,6 +21,7 @@ import com.carrotsearch.hppc.ObjectFloatOpenHashMap; import com.google.common.collect.Lists; + import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.unit.Fuzziness; @@ -404,4 +405,7 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio builder.endObject(); } + final protected String parserName() { + return MultiMatchQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java b/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java index 3fbd43651dec4..5d1afd68f87ba 100644 --- a/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.query; import com.google.common.collect.Maps; + import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.Query; import org.elasticsearch.common.inject.Inject; @@ -36,7 +37,7 @@ /** * Same as {@link MatchQueryParser} but has support for multiple fields. */ -public class MultiMatchQueryParser implements QueryParser { +public class MultiMatchQueryParser extends BaseQueryParserTemp { public static final String NAME = "multi_match"; diff --git a/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java index bd36fa9606e13..84f6ae2ac9a66 100644 --- a/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java @@ -113,4 +113,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.endObject(); } + final protected String parserName() { + return NestedQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/NestedQueryParser.java b/src/main/java/org/elasticsearch/index/query/NestedQueryParser.java index 989388b79d462..ede4055837fa3 100644 --- a/src/main/java/org/elasticsearch/index/query/NestedQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/NestedQueryParser.java @@ -37,7 +37,7 @@ import java.io.IOException; -public class NestedQueryParser implements QueryParser { +public class NestedQueryParser extends BaseQueryParserTemp { public static final String NAME = "nested"; diff --git a/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java index c5bea414f6cca..da5371a07fbb7 100644 --- a/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java @@ -95,4 +95,8 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio } builder.endObject(); } -} \ No newline at end of file + + final protected String parserName() { + return PrefixQueryParser.NAME; + } +} diff --git a/src/main/java/org/elasticsearch/index/query/PrefixQueryParser.java b/src/main/java/org/elasticsearch/index/query/PrefixQueryParser.java index 0cecb0aa651ff..baecdac974be4 100644 --- a/src/main/java/org/elasticsearch/index/query/PrefixQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/PrefixQueryParser.java @@ -34,7 +34,7 @@ /** * */ -public class PrefixQueryParser implements QueryParser { +public class PrefixQueryParser extends BaseQueryParserTemp { public static final String NAME = "prefix"; @@ -113,4 +113,4 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/QueryBuilder.java b/src/main/java/org/elasticsearch/index/query/QueryBuilder.java index c4d3588edceda..5ca44aa826a10 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/QueryBuilder.java @@ -19,17 +19,30 @@ package org.elasticsearch.index.query; +import org.apache.lucene.search.Query; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentType; +import java.io.IOException; + /** - * + * Base interface for all classes producing lucene queries. + * Supports conversion to BytesReference and creation of lucene Query objects. */ public interface QueryBuilder extends ToXContent { BytesReference buildAsBytes() throws ElasticsearchException; BytesReference buildAsBytes(XContentType contentType) throws ElasticsearchException; + + /** + * Create a {@link Query} based on this QueryBuilder + * @param parseContext additional information needed to construct the queries + * @return the {@link Query} + * @throws QueryParsingException + * @throws IOException + */ + Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException; } diff --git a/src/main/java/org/elasticsearch/index/query/QueryParseContext.java b/src/main/java/org/elasticsearch/index/query/QueryParseContext.java index fe6292735ca70..6b149f999375f 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryParseContext.java +++ b/src/main/java/org/elasticsearch/index/query/QueryParseContext.java @@ -156,7 +156,7 @@ public void parser(XContentParser parser) { public XContentParser parser() { return parser; } - + public IndexQueryParserService indexQueryParserService() { return indexQueryParser; } @@ -285,8 +285,11 @@ public void addInnerHits(String name, InnerHitsContext.BaseInnerHits context) { innerHitsContext.addInnerHitDefinition(name, context); } - @Nullable - public Query parseInnerQuery() throws IOException, QueryParsingException { + /** + * @return a new QueryBuilder based on the current state of the parser + * @throws IOException + */ + public QueryBuilder parseInnerQueryBuilder() throws IOException { // move to START object XContentParser.Token token; if (parser.currentToken() != XContentParser.Token.START_OBJECT) { @@ -310,22 +313,45 @@ public Query parseInnerQuery() throws IOException, QueryParsingException { if (queryParser == null) { throw new QueryParsingException(index, "No query registered for [" + queryName + "]"); } - Query result = queryParser.parse(this); + QueryBuilder result = queryParser.fromXContent(this); if (parser.currentToken() == XContentParser.Token.END_OBJECT || parser.currentToken() == XContentParser.Token.END_ARRAY) { // if we are at END_OBJECT, move to the next one... parser.nextToken(); } - if (result instanceof NoCacheQuery) { + return result; + } + + /** + * @deprecated replaced by calls to parseInnerQueryBuilder() and checkCachable() for the resulting queries + */ + @Nullable + @Deprecated + public Query parseInnerQuery() throws IOException, QueryParsingException { + QueryBuilder builder = parseInnerQueryBuilder(); + + Query result = builder.toQuery(this); + checkCachable(result); + return result; + } + + /** + * Checks if the given lucene query should be cached or wrapped, sets flags in this QueryParseContext accordingly + * @param query + */ + void checkCachable(Query query) { + if (query instanceof NoCacheQuery) { propagateNoCache = true; } - if (CustomQueryWrappingFilter.shouldUseCustomQueryWrappingFilter(result)) { + if (CustomQueryWrappingFilter.shouldUseCustomQueryWrappingFilter(query)) { requireCustomQueryWrappingFilter = true; - // If later on, either directly or indirectly this query gets wrapped in a query filter it must never - // get cached even if a filter higher up the chain is configured to do this. This will happen, because - // the result filter will be instance of NoCacheFilter (CustomQueryWrappingFilter) which will in + // If later on, either directly or indirectly this query gets + // wrapped in a query filter it must never + // get cached even if a filter higher up the chain is configured to + // do this. This will happen, because + // the result filter will be instance of NoCacheFilter + // (CustomQueryWrappingFilter) which will in // #executeFilterParser() set propagateNoCache to true. } - return result; } @Nullable @@ -481,4 +507,5 @@ public boolean requireCustomQueryWrappingFilter() { public NestedScope nestedScope() { return nestedScope; } + } diff --git a/src/main/java/org/elasticsearch/index/query/QueryParser.java b/src/main/java/org/elasticsearch/index/query/QueryParser.java index eff585a9426e2..b34761ab72021 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/QueryParser.java @@ -35,11 +35,27 @@ public interface QueryParser { String[] names(); /** - * Parses the into a query from the current parser location. Will be at "START_OBJECT" location, - * and should end when the token is at the matching "END_OBJECT". + * Parses the into a query from the current parser location. Will be at + * "START_OBJECT" location, and should end when the token is at the matching + * "END_OBJECT". *

- * Returns null if this query should be ignored in the context of the DSL. + * Returns null if this query should be ignored in the context of + * the DSL. */ @Nullable Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException; + + /** + * Create a new QueryBuilder from the query as XContent stored int the + * parseContext + * + * @param parseContext + * the input parse context. The state on the parser contained in + * this context will be changed as a side effect of this method + * call + * @return the new QueryBuilder + * @throws IOException + * @throws QueryParsingException + */ + QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException; } diff --git a/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java index d939a4654a243..1c85003639de8 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java @@ -433,4 +433,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + final protected String parserName() { + return QueryStringQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java b/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java index ded43bc50e89b..ffe5cdf644235 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java @@ -47,7 +47,7 @@ /** * */ -public class QueryStringQueryParser implements QueryParser { +public class QueryStringQueryParser extends BaseQueryParserTemp { public static final String NAME = "query_string"; private static final ParseField FUZZINESS = Fuzziness.FIELD.withDeprecation("fuzzy_min_sim"); diff --git a/src/main/java/org/elasticsearch/index/query/QueryWrappingQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/QueryWrappingQueryBuilder.java new file mode 100644 index 0000000000000..86f8c2ee3fb37 --- /dev/null +++ b/src/main/java/org/elasticsearch/index/query/QueryWrappingQueryBuilder.java @@ -0,0 +1,53 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.query; + +import org.apache.lucene.search.Query; +import org.elasticsearch.common.xcontent.XContentBuilder; + +import java.io.IOException; + +/** + * Temporary wrapper for keeping pre-parsed lucene query in a QueryBuilder field in nested queries. + * Can be removed after query refactoring is done. + */ +public class QueryWrappingQueryBuilder extends BaseQueryBuilder { + + private Query query; + + public QueryWrappingQueryBuilder(Query query) { + this.query = query; + } + + @Override + protected void doXContent(XContentBuilder builder, Params params) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException { + return this.query; + } + + final protected String parserName() { + // this should not be called since we overwrite BaseQueryBuilder#toQuery() in this class + throw new UnsupportedOperationException(); + } +} diff --git a/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java index 7ed99d6e57116..e57d54ba329f5 100644 --- a/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java @@ -428,4 +428,10 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.endObject(); builder.endObject(); } + + @Override + protected String parserName() { + return RangeQueryParser.NAME; + } + } diff --git a/src/main/java/org/elasticsearch/index/query/RangeQueryParser.java b/src/main/java/org/elasticsearch/index/query/RangeQueryParser.java index cfc600832ec4d..97458964582c3 100644 --- a/src/main/java/org/elasticsearch/index/query/RangeQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/RangeQueryParser.java @@ -36,7 +36,7 @@ /** * */ -public class RangeQueryParser implements QueryParser { +public class RangeQueryParser extends BaseQueryParserTemp { public static final String NAME = "range"; diff --git a/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java index 8d4ba6cefcae9..0356849a2074f 100644 --- a/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java @@ -124,4 +124,9 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio } builder.endObject(); } + + @Override + protected String parserName() { + return RegexpQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/RegexpQueryParser.java b/src/main/java/org/elasticsearch/index/query/RegexpQueryParser.java index 41d53316a5749..e1f4a4373e6c4 100644 --- a/src/main/java/org/elasticsearch/index/query/RegexpQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/RegexpQueryParser.java @@ -36,7 +36,7 @@ /** * */ -public class RegexpQueryParser implements QueryParser { +public class RegexpQueryParser extends BaseQueryParserTemp { public static final String NAME = "regexp"; diff --git a/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java b/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java index f0cc2bbeb6d43..17b206503e3c8 100644 --- a/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java @@ -198,4 +198,9 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio builder.endObject(); } + + @Override + protected String parserName() { + return SimpleQueryStringParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SimpleQueryStringParser.java b/src/main/java/org/elasticsearch/index/query/SimpleQueryStringParser.java index 43e64ce0280e1..1c074ea4fd9c1 100644 --- a/src/main/java/org/elasticsearch/index/query/SimpleQueryStringParser.java +++ b/src/main/java/org/elasticsearch/index/query/SimpleQueryStringParser.java @@ -69,7 +69,7 @@ * {@code fields} - fields to search, defaults to _all if not set, allows * boosting a field with ^n */ -public class SimpleQueryStringParser implements QueryParser { +public class SimpleQueryStringParser extends BaseQueryParserTemp { public static final String NAME = "simple_query_string"; diff --git a/src/main/java/org/elasticsearch/index/query/SpanFirstQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanFirstQueryBuilder.java index 5773538faec42..84f9834208d86 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanFirstQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanFirstQueryBuilder.java @@ -69,4 +69,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + @Override + protected String parserName() { + return SpanFirstQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanFirstQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanFirstQueryParser.java index ea8ff3d39238b..1caef178c30f8 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanFirstQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanFirstQueryParser.java @@ -31,7 +31,7 @@ /** * */ -public class SpanFirstQueryParser implements QueryParser { +public class SpanFirstQueryParser extends BaseQueryParserTemp { public static final String NAME = "span_first"; @@ -95,4 +95,4 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryBuilder.java index 72bc58dcb85cd..c629d40567c6e 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryBuilder.java @@ -42,4 +42,8 @@ protected void doXContent(XContentBuilder builder, Params params) builder.endObject(); } + @Override + protected String parserName() { + return SpanMultiTermQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryParser.java index 7c9b2a6727761..40f863851ac65 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryParser.java @@ -31,7 +31,7 @@ /** * */ -public class SpanMultiTermQueryParser implements QueryParser { +public class SpanMultiTermQueryParser extends BaseQueryParserTemp { public static final String NAME = "span_multi"; public static final String MATCH_NAME = "match"; diff --git a/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java index 286fab968ebd1..912e8d18f299b 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java @@ -105,4 +105,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + @Override + protected String parserName() { + return SpanNearQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanNearQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanNearQueryParser.java index 84283fce1a443..9c73eeef01649 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNearQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNearQueryParser.java @@ -34,7 +34,7 @@ /** * */ -public class SpanNearQueryParser implements QueryParser { +public class SpanNearQueryParser extends BaseQueryParserTemp { public static final String NAME = "span_near"; diff --git a/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java index cb14dae11d2c7..4d5acc61e250e 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java @@ -119,4 +119,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + @Override + protected String parserName() { + return SpanNotQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java index afadf4c68ef0f..e795c6925a874 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java @@ -31,7 +31,7 @@ /** * */ -public class SpanNotQueryParser implements QueryParser { +public class SpanNotQueryParser extends BaseQueryParserTemp { public static final String NAME = "span_not"; @@ -128,4 +128,4 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java index f780ed8b05dec..db00859d4c834 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java @@ -74,4 +74,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + @Override + protected String parserName() { + return SpanOrQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanOrQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanOrQueryParser.java index a9d12f6d94129..ae88f59b3e3cc 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanOrQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanOrQueryParser.java @@ -34,7 +34,7 @@ /** * */ -public class SpanOrQueryParser implements QueryParser { +public class SpanOrQueryParser extends BaseQueryParserTemp { public static final String NAME = "span_or"; @@ -94,4 +94,4 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java index 80b696edc14fa..8d9e619855e13 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java @@ -93,4 +93,9 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio } builder.endObject(); } -} \ No newline at end of file + + @Override + protected String parserName() { + return SpanTermQueryParser.NAME; + } +} diff --git a/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java index 0203bb2605145..be724d6ff72ee 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java @@ -33,7 +33,7 @@ /** * */ -public class SpanTermQueryParser implements QueryParser { +public class SpanTermQueryParser extends BaseQueryParserTemp { public static final String NAME = "span_term"; @@ -111,4 +111,4 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java index 176f97f4fff22..46342fd93dfc0 100644 --- a/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java @@ -77,4 +77,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field(TemplateQueryParser.PARAMS, vars); builder.endObject(); } + + @Override + protected String parserName() { + return TemplateQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/TemplateQueryParser.java b/src/main/java/org/elasticsearch/index/query/TemplateQueryParser.java index 41bf930e4a8c9..b38876c42ca46 100644 --- a/src/main/java/org/elasticsearch/index/query/TemplateQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/TemplateQueryParser.java @@ -38,7 +38,7 @@ * In the simplest case, parse template string and variables from the request, compile the template and * execute the template against the given variables. * */ -public class TemplateQueryParser implements QueryParser { +public class TemplateQueryParser extends BaseQueryParserTemp { /** Name to reference this type of query. */ public static final String NAME = "template"; diff --git a/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java index fbedfe33a8f87..db5837fd9fce8 100644 --- a/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java @@ -145,4 +145,9 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio } builder.endObject(); } + + @Override + protected String parserName() { + return TermQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/TermQueryParser.java b/src/main/java/org/elasticsearch/index/query/TermQueryParser.java index 2c016973b6ec2..acb92e3611b92 100644 --- a/src/main/java/org/elasticsearch/index/query/TermQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/TermQueryParser.java @@ -32,7 +32,7 @@ /** * */ -public class TermQueryParser implements QueryParser { +public class TermQueryParser extends BaseQueryParserTemp { public static final String NAME = "term"; diff --git a/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java index a18b3a858b9a2..a267ebe6e015c 100644 --- a/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java @@ -190,4 +190,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.endObject(); } + + @Override + protected String parserName() { + return TermsQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java b/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java index 15c9f18388ea2..3aab95b16214c 100644 --- a/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java @@ -44,7 +44,7 @@ * } * */ -public class TermsQueryParser implements QueryParser { +public class TermsQueryParser extends BaseQueryParserTemp { public static final String NAME = "terms"; diff --git a/src/main/java/org/elasticsearch/index/query/TopChildrenQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/TopChildrenQueryBuilder.java index a8174230db932..f5240415b2c57 100644 --- a/src/main/java/org/elasticsearch/index/query/TopChildrenQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/TopChildrenQueryBuilder.java @@ -113,4 +113,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endObject(); } + + @Override + protected String parserName() { + return TopChildrenQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/TopChildrenQueryParser.java b/src/main/java/org/elasticsearch/index/query/TopChildrenQueryParser.java index a0f5834b44eba..d49594a2a1860 100644 --- a/src/main/java/org/elasticsearch/index/query/TopChildrenQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/TopChildrenQueryParser.java @@ -40,7 +40,7 @@ /** * */ -public class TopChildrenQueryParser implements QueryParser { +public class TopChildrenQueryParser extends BaseQueryParserTemp { public static final String NAME = "top_children"; diff --git a/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java index 245404f4044aa..6b3ad18b52122 100644 --- a/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java @@ -105,4 +105,9 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio } builder.endObject(); } -} \ No newline at end of file + + @Override + protected String parserName() { + return WildcardQueryParser.NAME; + } +} diff --git a/src/main/java/org/elasticsearch/index/query/WildcardQueryParser.java b/src/main/java/org/elasticsearch/index/query/WildcardQueryParser.java index 6a641e9621934..3ba40e85129c4 100644 --- a/src/main/java/org/elasticsearch/index/query/WildcardQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/WildcardQueryParser.java @@ -33,7 +33,7 @@ /** * */ -public class WildcardQueryParser implements QueryParser { +public class WildcardQueryParser extends BaseQueryParserTemp { public static final String NAME = "wildcard"; @@ -110,4 +110,4 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return wildcardQuery; } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java index e3688a57f81a2..3deabf90a2e8b 100644 --- a/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java @@ -26,6 +26,7 @@ */ import com.google.common.base.Charsets; + import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -71,4 +72,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("query", source, offset, length); builder.endObject(); } + + @Override + protected String parserName() { + return WrapperQueryParser.NAME; + } } diff --git a/src/main/java/org/elasticsearch/index/query/WrapperQueryParser.java b/src/main/java/org/elasticsearch/index/query/WrapperQueryParser.java index 3fc16d7af7402..cfcce4ac9c90e 100644 --- a/src/main/java/org/elasticsearch/index/query/WrapperQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/WrapperQueryParser.java @@ -29,7 +29,7 @@ /** * Query parser for JSON Queries. */ -public class WrapperQueryParser implements QueryParser { +public class WrapperQueryParser extends BaseQueryParserTemp { public static final String NAME = "wrapper"; diff --git a/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java index 53804abfe6ce8..5b007730c947e 100644 --- a/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java @@ -21,7 +21,6 @@ import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.common.lucene.search.function.CombineFunction; -import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.BaseQueryBuilder; import org.elasticsearch.index.query.BoostableQueryBuilder; @@ -227,4 +226,9 @@ public FunctionScoreQueryBuilder setMinScore(float minScore) { this.minScore = minScore; return this; } -} \ No newline at end of file + + @Override + protected String parserName() { + return FunctionScoreQueryParser.NAME; + } +} diff --git a/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java b/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java index 92bfd31035c60..b442abffd621a 100644 --- a/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java @@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; + import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.Filter; import org.apache.lucene.search.FilteredQuery; @@ -37,9 +38,11 @@ import org.elasticsearch.common.lucene.search.function.ScoreFunction; import org.elasticsearch.common.lucene.search.function.WeightFactorFunction; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParser; import org.elasticsearch.index.query.QueryParsingException; +import org.elasticsearch.index.query.QueryWrappingQueryBuilder; import org.elasticsearch.index.query.functionscore.factor.FactorParser; import java.io.IOException; @@ -265,4 +268,10 @@ private CombineFunction parseBoostMode(QueryParseContext parseContext, XContentP } return cf; } -} \ No newline at end of file + + @Override + public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException { + Query query = parse(parseContext); + return new QueryWrappingQueryBuilder(query); + } +} diff --git a/src/test/java/org/elasticsearch/index/query/guice/MyJsonQueryParser.java b/src/test/java/org/elasticsearch/index/query/guice/MyJsonQueryParser.java index 582ef1313e788..89c203835fcc7 100644 --- a/src/test/java/org/elasticsearch/index/query/guice/MyJsonQueryParser.java +++ b/src/test/java/org/elasticsearch/index/query/guice/MyJsonQueryParser.java @@ -25,9 +25,11 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; +import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParser; import org.elasticsearch.index.query.QueryParsingException; +import org.elasticsearch.index.query.QueryWrappingQueryBuilder; import org.elasticsearch.index.settings.IndexSettings; import java.io.IOException; @@ -61,4 +63,10 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars public Settings settings() { return settings; } + + @Override + public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException { + Query query = parse(parseContext); + return new QueryWrappingQueryBuilder(query); + } } diff --git a/src/test/java/org/elasticsearch/index/query/plugin/PluginJsonQueryParser.java b/src/test/java/org/elasticsearch/index/query/plugin/PluginJsonQueryParser.java index d475cdfefae88..d67fc7c72cca6 100644 --- a/src/test/java/org/elasticsearch/index/query/plugin/PluginJsonQueryParser.java +++ b/src/test/java/org/elasticsearch/index/query/plugin/PluginJsonQueryParser.java @@ -25,9 +25,11 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; +import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParser; import org.elasticsearch.index.query.QueryParsingException; +import org.elasticsearch.index.query.QueryWrappingQueryBuilder; import org.elasticsearch.index.settings.IndexSettings; import java.io.IOException; @@ -61,4 +63,10 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars public Settings settings() { return settings; } + + @Override + public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException { + Query query = parse(parseContext); + return new QueryWrappingQueryBuilder(query); + } } \ No newline at end of file