From 1e9399745177a8e7d3b9758008413bfd2c95536a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 22 May 2015 17:07:39 +0200 Subject: [PATCH] Query refactoring: Adding getBuilderPrototype() method to all QueryParsers Currently there is a registry for all QueryParsers accessible via the IndicesQueriesModule. For deserializing nested queries e.g. for the BoolQueryBuilder (#11121) we need to look up query builders by their name to be able to deserialize using a prototype builder of the concrete class. This PR adds a getBuilderPrototype() method to each query parser so we can re-use the parser registry to get the corresponding builder using the query name. Closes #11344 --- .../elasticsearch/index/query/AndQueryBuilder.java | 2 ++ .../elasticsearch/index/query/AndQueryParser.java | 5 +++++ .../elasticsearch/index/query/BoolQueryBuilder.java | 2 ++ .../elasticsearch/index/query/BoolQueryParser.java | 5 +++++ .../index/query/BoostingQueryBuilder.java | 3 ++- .../index/query/BoostingQueryParser.java | 5 +++++ .../index/query/CommonTermsQueryBuilder.java | 10 ++++++++++ .../index/query/CommonTermsQueryParser.java | 5 +++++ .../index/query/ConstantScoreQueryBuilder.java | 9 +++++++++ .../index/query/ConstantScoreQueryParser.java | 5 +++++ .../index/query/DisMaxQueryBuilder.java | 2 ++ .../index/query/DisMaxQueryParser.java | 5 +++++ .../index/query/ExistsQueryBuilder.java | 2 ++ .../index/query/ExistsQueryParser.java | 5 +++++ .../index/query/FQueryFilterParser.java | 5 +++++ .../index/query/FieldMaskingSpanQueryBuilder.java | 2 ++ .../index/query/FieldMaskingSpanQueryParser.java | 5 +++++ .../index/query/FilteredQueryBuilder.java | 2 ++ .../index/query/FilteredQueryParser.java | 5 +++++ .../index/query/FuzzyQueryBuilder.java | 2 ++ .../elasticsearch/index/query/FuzzyQueryParser.java | 5 +++++ .../index/query/GeoBoundingBoxQueryBuilder.java | 2 ++ .../index/query/GeoBoundingBoxQueryParser.java | 13 +++++++++---- .../index/query/GeoDistanceQueryBuilder.java | 2 ++ .../index/query/GeoDistanceQueryParser.java | 5 +++++ .../index/query/GeoDistanceRangeQueryBuilder.java | 2 ++ .../index/query/GeoDistanceRangeQueryParser.java | 5 +++++ .../index/query/GeoPolygonQueryBuilder.java | 2 ++ .../index/query/GeoPolygonQueryParser.java | 5 +++++ .../index/query/GeoShapeQueryBuilder.java | 2 ++ .../index/query/GeoShapeQueryParser.java | 5 +++++ .../elasticsearch/index/query/GeohashCellQuery.java | 6 ++++++ .../index/query/HasChildQueryBuilder.java | 2 ++ .../index/query/HasChildQueryParser.java | 5 +++++ .../index/query/HasParentQueryBuilder.java | 1 + .../index/query/HasParentQueryParser.java | 5 +++++ .../elasticsearch/index/query/IdsQueryBuilder.java | 3 +++ .../elasticsearch/index/query/IdsQueryParser.java | 5 +++++ .../index/query/IndicesQueryBuilder.java | 2 ++ .../index/query/IndicesQueryParser.java | 5 +++++ .../index/query/LimitQueryBuilder.java | 1 + .../elasticsearch/index/query/LimitQueryParser.java | 5 +++++ .../index/query/MatchAllQueryBuilder.java | 2 ++ .../index/query/MatchAllQueryParser.java | 5 +++++ .../index/query/MatchQueryBuilder.java | 2 ++ .../elasticsearch/index/query/MatchQueryParser.java | 5 +++++ .../index/query/MissingQueryBuilder.java | 2 ++ .../index/query/MissingQueryParser.java | 5 +++++ .../index/query/MoreLikeThisQueryBuilder.java | 2 ++ .../index/query/MoreLikeThisQueryParser.java | 5 +++++ .../index/query/MultiMatchQueryBuilder.java | 2 ++ .../index/query/MultiMatchQueryParser.java | 5 +++++ .../index/query/NestedQueryBuilder.java | 11 +++++++++++ .../index/query/NestedQueryParser.java | 5 +++++ .../elasticsearch/index/query/NotQueryBuilder.java | 9 +++++++++ .../elasticsearch/index/query/NotQueryParser.java | 5 +++++ .../elasticsearch/index/query/OrQueryBuilder.java | 2 ++ .../elasticsearch/index/query/OrQueryParser.java | 5 +++++ .../index/query/PrefixQueryBuilder.java | 2 ++ .../index/query/PrefixQueryParser.java | 5 +++++ .../index/query/QueryFilterBuilder.java | 2 ++ .../index/query/QueryFilterParser.java | 5 +++++ .../org/elasticsearch/index/query/QueryParser.java | 5 +++++ .../index/query/QueryStringQueryBuilder.java | 2 ++ .../index/query/QueryStringQueryParser.java | 5 +++++ .../index/query/RangeQueryBuilder.java | 2 ++ .../elasticsearch/index/query/RangeQueryParser.java | 8 +++++--- .../index/query/RegexpQueryBuilder.java | 1 + .../index/query/RegexpQueryParser.java | 5 +++++ .../index/query/ScriptQueryBuilder.java | 2 ++ .../index/query/ScriptQueryParser.java | 5 +++++ .../index/query/SimpleQueryStringBuilder.java | 1 + .../index/query/SimpleQueryStringParser.java | 5 +++++ .../index/query/SpanContainingQueryBuilder.java | 1 + .../index/query/SpanContainingQueryParser.java | 5 +++++ .../index/query/SpanFirstQueryBuilder.java | 2 ++ .../index/query/SpanFirstQueryParser.java | 5 +++++ .../index/query/SpanMultiTermQueryBuilder.java | 1 + .../index/query/SpanMultiTermQueryParser.java | 5 +++++ .../index/query/SpanNearQueryBuilder.java | 2 ++ .../index/query/SpanNearQueryParser.java | 5 +++++ .../index/query/SpanNotQueryBuilder.java | 2 ++ .../index/query/SpanNotQueryParser.java | 5 +++++ .../index/query/SpanOrQueryBuilder.java | 2 ++ .../index/query/SpanOrQueryParser.java | 5 +++++ .../index/query/SpanTermQueryBuilder.java | 1 + .../index/query/SpanTermQueryParser.java | 5 +++++ .../index/query/SpanWithinQueryBuilder.java | 1 + .../index/query/SpanWithinQueryParser.java | 5 +++++ .../index/query/TemplateQueryBuilder.java | 2 ++ .../index/query/TemplateQueryParser.java | 5 +++++ .../elasticsearch/index/query/TermQueryBuilder.java | 1 + .../elasticsearch/index/query/TermQueryParser.java | 6 +++++- .../index/query/TermsQueryBuilder.java | 2 ++ .../elasticsearch/index/query/TermsQueryParser.java | 5 +++++ .../elasticsearch/index/query/TypeQueryBuilder.java | 1 + .../elasticsearch/index/query/TypeQueryParser.java | 7 ++++++- .../index/query/WildcardQueryBuilder.java | 2 ++ .../index/query/WildcardQueryParser.java | 5 +++++ .../index/query/WrapperQueryBuilder.java | 1 + .../index/query/WrapperQueryParser.java | 5 +++++ .../functionscore/FunctionScoreQueryBuilder.java | 2 ++ .../functionscore/FunctionScoreQueryParser.java | 5 +++++ .../index/query/SimpleIndexQueryParserTests.java | 5 +++++ .../index/query/guice/MyJsonQueryParser.java | 5 +++++ .../index/query/plugin/PluginJsonQueryParser.java | 5 +++++ 106 files changed, 407 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/query/AndQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/AndQueryBuilder.java index 1492a70d01ce0..ecc632744264d 100644 --- a/src/main/java/org/elasticsearch/index/query/AndQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/AndQueryBuilder.java @@ -39,6 +39,8 @@ public class AndQueryBuilder extends QueryBuilder { private String queryName; + static final AndQueryBuilder PROTOTYPE = new AndQueryBuilder(); + public AndQueryBuilder(QueryBuilder... filters) { for (QueryBuilder filter : filters) { this.filters.add(filter); diff --git a/src/main/java/org/elasticsearch/index/query/AndQueryParser.java b/src/main/java/org/elasticsearch/index/query/AndQueryParser.java index afafcdb723ddc..601d69e5700d6 100644 --- a/src/main/java/org/elasticsearch/index/query/AndQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/AndQueryParser.java @@ -115,4 +115,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public AndQueryBuilder getBuilderPrototype() { + return AndQueryBuilder.PROTOTYPE; + } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java index 9d39344a71f60..6977e100a4fe9 100644 --- a/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java @@ -51,6 +51,8 @@ public class BoolQueryBuilder extends QueryBuilder implements BoostableQueryBuil private String queryName; + static final BoolQueryBuilder PROTOTYPE = new BoolQueryBuilder(); + /** * Adds a query that must appear in the matching documents and will * contribute to scoring. diff --git a/src/main/java/org/elasticsearch/index/query/BoolQueryParser.java b/src/main/java/org/elasticsearch/index/query/BoolQueryParser.java index 403f65d04dd5c..34a947c302f86 100644 --- a/src/main/java/org/elasticsearch/index/query/BoolQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/BoolQueryParser.java @@ -171,4 +171,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public BoolQueryBuilder getBuilderPrototype() { + return BoolQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java index 9c6762602ba24..7a67ce3a60332 100644 --- a/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java @@ -47,8 +47,9 @@ public class BoostingQueryBuilder extends QueryBuilder implements BoostableQuery private float boost = -1; - public BoostingQueryBuilder() { + static final BoostingQueryBuilder PROTOTYPE = new BoostingQueryBuilder(); + public BoostingQueryBuilder() { } public BoostingQueryBuilder positive(QueryBuilder positiveQuery) { diff --git a/src/main/java/org/elasticsearch/index/query/BoostingQueryParser.java b/src/main/java/org/elasticsearch/index/query/BoostingQueryParser.java index 89f87a575511e..897cabaf33c1c 100644 --- a/src/main/java/org/elasticsearch/index/query/BoostingQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/BoostingQueryParser.java @@ -98,4 +98,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return boostingQuery; } + + @Override + public BoostingQueryBuilder getBuilderPrototype() { + return BoostingQueryBuilder.PROTOTYPE; + } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java index f5960c814a226..7f016c8b2ff02 100644 --- a/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java @@ -72,6 +72,8 @@ public static enum Operator { private String queryName; + static final CommonTermsQueryBuilder PROTOTYPE = new CommonTermsQueryBuilder(); + /** * Constructs a new common terms query. */ @@ -86,6 +88,14 @@ public CommonTermsQueryBuilder(String name, Object text) { this.name = name; } + /** + * private constructor used onyl internally + */ + private CommonTermsQueryBuilder() { + this.text = null; + this.name = null; + } + /** * Sets the operator to use for terms with a high document frequency * (greater than or equal to {@link #cutoffFrequency(float)}. Defaults to diff --git a/src/main/java/org/elasticsearch/index/query/CommonTermsQueryParser.java b/src/main/java/org/elasticsearch/index/query/CommonTermsQueryParser.java index 54322e1722677..7e261568361a8 100644 --- a/src/main/java/org/elasticsearch/index/query/CommonTermsQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/CommonTermsQueryParser.java @@ -219,4 +219,9 @@ private final Query parseQueryString(ExtendedCommonTermsQuery query, String quer query.setHighFreqMinimumNumberShouldMatch(highFreqMinimumShouldMatch); return query; } + + @Override + public CommonTermsQueryBuilder getBuilderPrototype() { + return CommonTermsQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java index 0ca9470d2f86c..53b2a7bc757c6 100644 --- a/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java @@ -37,6 +37,8 @@ public class ConstantScoreQueryBuilder extends QueryBuilder implements Boostable private float boost = -1; + static final ConstantScoreQueryBuilder PROTOTYPE = new ConstantScoreQueryBuilder(); + /** * A query that wraps a query and simply returns a constant score equal to the * query boost for every document in the query. @@ -47,6 +49,13 @@ public ConstantScoreQueryBuilder(QueryBuilder filterBuilder) { this.filterBuilder = Objects.requireNonNull(filterBuilder); } + /** + * private constructor only used for serialization + */ + private ConstantScoreQueryBuilder() { + this.filterBuilder = null; + } + /** * Sets the boost for this query. Documents matching this query will (in addition to the normal * weightings) have their score multiplied by the boost provided. diff --git a/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryParser.java b/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryParser.java index 6545a4086fd00..504eb8d5a74a4 100644 --- a/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryParser.java @@ -86,4 +86,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars filter.setBoost(boost); return filter; } + + @Override + public ConstantScoreQueryBuilder getBuilderPrototype() { + return ConstantScoreQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java index 410fd1cc55529..a6927899412f9 100644 --- a/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java @@ -43,6 +43,8 @@ public class DisMaxQueryBuilder extends QueryBuilder implements BoostableQueryBu private String queryName; + static final DisMaxQueryBuilder PROTOTYPE = new DisMaxQueryBuilder(); + /** * Add a sub-query to this disjunction. */ diff --git a/src/main/java/org/elasticsearch/index/query/DisMaxQueryParser.java b/src/main/java/org/elasticsearch/index/query/DisMaxQueryParser.java index 145890ae17d03..20ff932514799 100644 --- a/src/main/java/org/elasticsearch/index/query/DisMaxQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/DisMaxQueryParser.java @@ -111,4 +111,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public DisMaxQueryBuilder getBuilderPrototype() { + return DisMaxQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java index 8e25be30292a9..f59b861a9e62e 100644 --- a/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java @@ -34,6 +34,8 @@ public class ExistsQueryBuilder extends QueryBuilder { private String queryName; + static final ExistsQueryBuilder PROTOTYPE = new ExistsQueryBuilder(null); + public ExistsQueryBuilder(String name) { this.name = name; } diff --git a/src/main/java/org/elasticsearch/index/query/ExistsQueryParser.java b/src/main/java/org/elasticsearch/index/query/ExistsQueryParser.java index 1a35dfbbaebe3..3da9a66b84335 100644 --- a/src/main/java/org/elasticsearch/index/query/ExistsQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/ExistsQueryParser.java @@ -122,4 +122,9 @@ public static Query newFilter(QueryParseContext parseContext, String fieldPatter return new ConstantScoreQuery(boolFilter); } + @Override + public ExistsQueryBuilder getBuilderPrototype() { + return ExistsQueryBuilder.PROTOTYPE; + } + } diff --git a/src/main/java/org/elasticsearch/index/query/FQueryFilterParser.java b/src/main/java/org/elasticsearch/index/query/FQueryFilterParser.java index 25851d718f8bc..9003c7c16f015 100644 --- a/src/main/java/org/elasticsearch/index/query/FQueryFilterParser.java +++ b/src/main/java/org/elasticsearch/index/query/FQueryFilterParser.java @@ -84,4 +84,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public QueryFilterBuilder getBuilderPrototype() { + return QueryFilterBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java index ac6c19ecc0cb5..acd0a38265f2b 100644 --- a/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java @@ -35,6 +35,8 @@ public class FieldMaskingSpanQueryBuilder extends QueryBuilder implements SpanQu private String queryName; + static final FieldMaskingSpanQueryBuilder PROTOTYPE = new FieldMaskingSpanQueryBuilder(null, null); + public FieldMaskingSpanQueryBuilder(SpanQueryBuilder queryBuilder, String field) { this.queryBuilder = queryBuilder; this.field = field; diff --git a/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryParser.java b/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryParser.java index e072fdb6fd3ea..aafa33ad3fcb7 100644 --- a/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryParser.java @@ -100,4 +100,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public FieldMaskingSpanQueryBuilder getBuilderPrototype() { + return FieldMaskingSpanQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java index a1955d556ed8c..900934618967e 100644 --- a/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java @@ -41,6 +41,8 @@ public class FilteredQueryBuilder extends QueryBuilder implements BoostableQuery private String queryName; + static final FilteredQueryBuilder PROTOTYPE = new FilteredQueryBuilder(null, null); + /** * A query that applies a filter to the results of another query. * diff --git a/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java b/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java index 8e4b701a78ac9..d9153e72bc440 100644 --- a/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java @@ -118,4 +118,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return filteredQuery; } + + @Override + public FilteredQueryBuilder getBuilderPrototype() { + return FilteredQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java index 6790a0c8d2926..9f222917e75bf 100644 --- a/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java @@ -50,6 +50,8 @@ public class FuzzyQueryBuilder extends MultiTermQueryBuilder implements Boostabl private String queryName; + static final FuzzyQueryBuilder PROTOTYPE = new FuzzyQueryBuilder(null, null); + /** * Constructs a new term query. * diff --git a/src/main/java/org/elasticsearch/index/query/FuzzyQueryParser.java b/src/main/java/org/elasticsearch/index/query/FuzzyQueryParser.java index 0595c7ce6e23e..dde7da8b65f86 100644 --- a/src/main/java/org/elasticsearch/index/query/FuzzyQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/FuzzyQueryParser.java @@ -130,4 +130,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public FuzzyQueryBuilder getBuilderPrototype() { + return FuzzyQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java index 4f6f1552c7b7c..f334cac1ebfd7 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java @@ -44,6 +44,8 @@ public class GeoBoundingBoxQueryBuilder extends QueryBuilder { private String queryName; private String type; + static final GeoBoundingBoxQueryBuilder PROTOTYPE = new GeoBoundingBoxQueryBuilder(null); + public GeoBoundingBoxQueryBuilder(String name) { this.name = name; } diff --git a/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryParser.java b/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryParser.java index 22cb24d79f824..daf4c269634ab 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryParser.java @@ -74,14 +74,14 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars double bottom = Double.NaN; double left = Double.NaN; double right = Double.NaN; - + String queryName = null; String currentFieldName = null; XContentParser.Token token; boolean normalize = true; GeoPoint sparse = new GeoPoint(); - + String type = "memory"; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -148,7 +148,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars final GeoPoint bottomRight = new GeoPoint(bottom, right); if (normalize) { - // Special case: if the difference bettween the left and right is 360 and the right is greater than the left, we are asking for + // Special case: if the difference bettween the left and right is 360 and the right is greater than the left, we are asking for // the complete longitude range so need to set longitude to the complete longditude range boolean completeLonRange = ((right - left) % 360 == 0 && right > left); GeoUtils.normalizePoint(topLeft, true, !completeLonRange); @@ -183,5 +183,10 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars parseContext.addNamedQuery(queryName, filter); } return filter; - } + } + + @Override + public GeoBoundingBoxQueryBuilder getBuilderPrototype() { + return GeoBoundingBoxQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/GeoDistanceQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/GeoDistanceQueryBuilder.java index 3b7551bc55557..066bdaee85a9d 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoDistanceQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/GeoDistanceQueryBuilder.java @@ -46,6 +46,8 @@ public class GeoDistanceQueryBuilder extends QueryBuilder { private String queryName; + static final GeoDistanceQueryBuilder PROTOTYPE = new GeoDistanceQueryBuilder(null); + public GeoDistanceQueryBuilder(String name) { this.name = name; } diff --git a/src/main/java/org/elasticsearch/index/query/GeoDistanceQueryParser.java b/src/main/java/org/elasticsearch/index/query/GeoDistanceQueryParser.java index ea588b8bfd2c6..6f3efe0868299 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoDistanceQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/GeoDistanceQueryParser.java @@ -162,4 +162,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public GeoDistanceQueryBuilder getBuilderPrototype() { + return GeoDistanceQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/GeoDistanceRangeQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/GeoDistanceRangeQueryBuilder.java index 467929ea9d313..85466fe30a407 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoDistanceRangeQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/GeoDistanceRangeQueryBuilder.java @@ -48,6 +48,8 @@ public class GeoDistanceRangeQueryBuilder extends QueryBuilder { private String optimizeBbox; + static final GeoDistanceRangeQueryBuilder PROTOTYPE = new GeoDistanceRangeQueryBuilder(null); + public GeoDistanceRangeQueryBuilder(String name) { this.name = name; } diff --git a/src/main/java/org/elasticsearch/index/query/GeoDistanceRangeQueryParser.java b/src/main/java/org/elasticsearch/index/query/GeoDistanceRangeQueryParser.java index a55bd3265d93d..4c2ef538066b5 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoDistanceRangeQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/GeoDistanceRangeQueryParser.java @@ -201,4 +201,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public GeoDistanceRangeQueryBuilder getBuilderPrototype() { + return GeoDistanceRangeQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryBuilder.java index 4ba38cd94d338..cf2c96e02feaa 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryBuilder.java @@ -40,6 +40,8 @@ public class GeoPolygonQueryBuilder extends QueryBuilder { private String queryName; + static final GeoPolygonQueryBuilder PROTOTYPE = new GeoPolygonQueryBuilder(null); + public GeoPolygonQueryBuilder(String name) { this.name = name; } diff --git a/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryParser.java b/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryParser.java index ea1fa7b67b012..12ae0aa90bb73 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryParser.java @@ -150,4 +150,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public GeoPolygonQueryBuilder getBuilderPrototype() { + return GeoPolygonQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java index df57ba9d5f66b..4e901892ed377 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java @@ -49,6 +49,8 @@ public class GeoShapeQueryBuilder extends QueryBuilder { private ShapeRelation relation = null; + static final GeoShapeQueryBuilder PROTOTYPE = new GeoShapeQueryBuilder(null, null); + /** * Creates a new GeoShapeQueryBuilder whose Filter will be against the * given field name using the given Shape diff --git a/src/main/java/org/elasticsearch/index/query/GeoShapeQueryParser.java b/src/main/java/org/elasticsearch/index/query/GeoShapeQueryParser.java index 9e3478f835816..dae2762e22bf3 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoShapeQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/GeoShapeQueryParser.java @@ -189,4 +189,9 @@ public static SpatialArgs getArgs(ShapeBuilder shape, ShapeRelation relation) { throw new IllegalArgumentException(""); } } + + @Override + public GeoShapeQueryBuilder getBuilderPrototype() { + return GeoShapeQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/GeohashCellQuery.java b/src/main/java/org/elasticsearch/index/query/GeohashCellQuery.java index c84070e0b4fff..b95d059ddf729 100644 --- a/src/main/java/org/elasticsearch/index/query/GeohashCellQuery.java +++ b/src/main/java/org/elasticsearch/index/query/GeohashCellQuery.java @@ -98,6 +98,7 @@ public static class Builder extends QueryBuilder { private String geohash; private int levels = -1; private boolean neighbors; + private static final Builder PROTOTYPE = new Builder(null); public Builder(String field) { @@ -270,5 +271,10 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars return filter; } + + @Override + public GeohashCellQuery.Builder getBuilderPrototype() { + return Builder.PROTOTYPE; + } } } diff --git a/src/main/java/org/elasticsearch/index/query/HasChildQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/HasChildQueryBuilder.java index cbd869a20c385..036eb69446804 100644 --- a/src/main/java/org/elasticsearch/index/query/HasChildQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/HasChildQueryBuilder.java @@ -45,6 +45,8 @@ public class HasChildQueryBuilder extends QueryBuilder implements BoostableQuery private QueryInnerHitBuilder innerHit = null; + static final HasChildQueryBuilder PROTOTYPE = new HasChildQueryBuilder(null, null); + public HasChildQueryBuilder(String type, QueryBuilder queryBuilder) { this.childType = type; this.queryBuilder = queryBuilder; diff --git a/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java b/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java index 5af04c6d29e47..d0efd97a695df 100644 --- a/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java @@ -187,4 +187,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars query.setBoost(boost); return query; } + + @Override + public HasChildQueryBuilder getBuilderPrototype() { + return HasChildQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/HasParentQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/HasParentQueryBuilder.java index e422be8f419a8..9226a5e38a02e 100644 --- a/src/main/java/org/elasticsearch/index/query/HasParentQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/HasParentQueryBuilder.java @@ -35,6 +35,7 @@ public class HasParentQueryBuilder extends QueryBuilder implements BoostableQuer private float boost = 1.0f; private String queryName; private QueryInnerHitBuilder innerHit = null; + static final HasParentQueryBuilder PROTOTYPE = new HasParentQueryBuilder(null, null); /** * @param parentType The parent type diff --git a/src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java b/src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java index 287b2178b542b..6ff290075d6f7 100644 --- a/src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java @@ -203,4 +203,9 @@ static Query createParentQuery(Query innerQuery, String parentType, boolean scor } } + @Override + public HasParentQueryBuilder getBuilderPrototype() { + return HasParentQueryBuilder.PROTOTYPE; + } + } diff --git a/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java index 4be719fdd2314..7d54c0479ecd6 100644 --- a/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.query; import com.google.common.collect.Sets; + import org.apache.lucene.queries.TermsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.cluster.metadata.MetaData; @@ -49,6 +50,8 @@ public class IdsQueryBuilder extends QueryBuilder implements Bo private String queryName; + static final IdsQueryBuilder PROTOTYPE = new IdsQueryBuilder(); + /** * Creates a new IdsQueryBuilder by optionally providing the types of the documents to look for */ diff --git a/src/main/java/org/elasticsearch/index/query/IdsQueryParser.java b/src/main/java/org/elasticsearch/index/query/IdsQueryParser.java index 48af1f107a05c..5ce95deaff30b 100644 --- a/src/main/java/org/elasticsearch/index/query/IdsQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/IdsQueryParser.java @@ -107,4 +107,9 @@ public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOExcept query.validate(); return query; } + + @Override + public IdsQueryBuilder getBuilderPrototype() { + return IdsQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java index 4e3cce865278c..c251157a16143 100644 --- a/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java @@ -40,6 +40,8 @@ public class IndicesQueryBuilder extends QueryBuilder { private String queryName; + static final IndicesQueryBuilder PROTOTYPE = new IndicesQueryBuilder(null); + public IndicesQueryBuilder(QueryBuilder queryBuilder, String... indices) { this.queryBuilder = queryBuilder; this.indices = indices; diff --git a/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java b/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java index c77e6c53fe2d2..a369f7038726a 100644 --- a/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java @@ -157,4 +157,9 @@ protected boolean matchesIndices(String currentIndex, String... indices) { } return false; } + + @Override + public IndicesQueryBuilder getBuilderPrototype() { + return IndicesQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/LimitQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/LimitQueryBuilder.java index 76d4148cceb3d..f397d216ba354 100644 --- a/src/main/java/org/elasticsearch/index/query/LimitQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/LimitQueryBuilder.java @@ -32,6 +32,7 @@ public class LimitQueryBuilder extends QueryBuilder { public static final String NAME = "limit"; private final int limit; + static final LimitQueryBuilder PROTOTYPE = new LimitQueryBuilder(-1); public LimitQueryBuilder(int limit) { this.limit = limit; diff --git a/src/main/java/org/elasticsearch/index/query/LimitQueryParser.java b/src/main/java/org/elasticsearch/index/query/LimitQueryParser.java index 87692ed19d2a9..ce4b88aaf57d9 100644 --- a/src/main/java/org/elasticsearch/index/query/LimitQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/LimitQueryParser.java @@ -64,4 +64,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars // this filter is deprecated and parses to a filter that matches everything return Queries.newMatchAllQuery(); } + + @Override + public LimitQueryBuilder getBuilderPrototype() { + return LimitQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java index 992acc6dd7a5a..f9407fbefa8e1 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MatchAllQueryBuilder.java @@ -37,6 +37,8 @@ public class MatchAllQueryBuilder extends QueryBuilder imp private float boost = 1.0f; + static final MatchAllQueryBuilder PROTOTYPE = new MatchAllQueryBuilder(); + /** * Sets the boost for this query. Documents matching this query will (in addition to the normal * weightings) have their score multiplied by the boost provided. diff --git a/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java b/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java index 8e46e1d000d2a..157d6d72a2b46 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MatchAllQueryParser.java @@ -59,4 +59,9 @@ public MatchAllQueryBuilder fromXContent(QueryParseContext parseContext) throws } return queryBuilder; } + + @Override + public MatchAllQueryBuilder getBuilderPrototype() { + return MatchAllQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java index 2459cf6591d34..a2a0e5124d4f8 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java @@ -94,6 +94,8 @@ public enum ZeroTermsQuery { private String queryName; + static final MatchQueryBuilder PROTOTYPE = new MatchQueryBuilder(null, null); + /** * Constructs a new text query. */ diff --git a/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java b/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java index 805ff107c2496..ddac7083c0aeb 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java @@ -178,4 +178,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public MatchQueryBuilder getBuilderPrototype() { + return MatchQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/MissingQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MissingQueryBuilder.java index 9b6c1cdf85729..a643110e8a484 100644 --- a/src/main/java/org/elasticsearch/index/query/MissingQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MissingQueryBuilder.java @@ -38,6 +38,8 @@ public class MissingQueryBuilder extends QueryBuilder { private Boolean existence; + static final MissingQueryBuilder PROTOTYPE = new MissingQueryBuilder(null); + public MissingQueryBuilder(String name) { this.name = name; } diff --git a/src/main/java/org/elasticsearch/index/query/MissingQueryParser.java b/src/main/java/org/elasticsearch/index/query/MissingQueryParser.java index 548831f9fd368..e0a25f6b8062a 100644 --- a/src/main/java/org/elasticsearch/index/query/MissingQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MissingQueryParser.java @@ -172,4 +172,9 @@ public static Query newFilter(QueryParseContext parseContext, String fieldPatter } return new ConstantScoreQuery(filter); } + + @Override + public MissingQueryBuilder getBuilderPrototype() { + return MissingQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index f59c5b6202769..209f6bc0eddef 100644 --- a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -152,6 +152,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws private Boolean failOnUnsupportedField; private String queryName; + static final MoreLikeThisQueryBuilder PROTOTYPE = new MoreLikeThisQueryBuilder(); + /** * Constructs a new more like this query which uses the "_all" field. */ diff --git a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java index 5122830c96567..143cf610a6ce4 100644 --- a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java @@ -355,4 +355,9 @@ private void handleExclude(BooleanQuery boolQuery, MultiTermVectorsRequest likeI boolQuery.add(query, BooleanClause.Occur.MUST_NOT); } } + + @Override + public MoreLikeThisQueryBuilder getBuilderPrototype() { + return MoreLikeThisQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java index 1a3fe0ac52af8..3113ec3292a47 100644 --- a/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java @@ -80,6 +80,8 @@ public class MultiMatchQueryBuilder extends QueryBuilder implements BoostableQue private String queryName; + static final MultiMatchQueryBuilder PROTOTYPE = new MultiMatchQueryBuilder(null); + public enum Type { /** diff --git a/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java b/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java index 5bbb777d091aa..0a4a05c677266 100644 --- a/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java @@ -197,4 +197,9 @@ private void extractFieldAndBoost(QueryParseContext parseContext, XContentParser fieldNameWithBoosts.put(fField, fBoost); } } + + @Override + public MultiMatchQueryBuilder getBuilderPrototype() { + return MultiMatchQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java index 50f7d5cd4bbb9..ab1252abadb23 100644 --- a/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java @@ -41,10 +41,21 @@ public class NestedQueryBuilder extends QueryBuilder implements BoostableQueryBu private QueryInnerHitBuilder innerHit; + static final NestedQueryBuilder PROTOTYPE = new NestedQueryBuilder(); + public NestedQueryBuilder(String path, QueryBuilder queryBuilder) { this.path = path; this.queryBuilder = Objects.requireNonNull(queryBuilder); } + + /** + * private constructor only used internally + */ + private NestedQueryBuilder() { + this.path = null; + this.queryBuilder = null; + } + /** * The score mode. */ diff --git a/src/main/java/org/elasticsearch/index/query/NestedQueryParser.java b/src/main/java/org/elasticsearch/index/query/NestedQueryParser.java index a353314c59326..b0ced1c8f25dc 100644 --- a/src/main/java/org/elasticsearch/index/query/NestedQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/NestedQueryParser.java @@ -161,4 +161,9 @@ public ToParentBlockJoinQuery build() throws IOException { } } + + @Override + public NestedQueryBuilder getBuilderPrototype() { + return NestedQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/NotQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/NotQueryBuilder.java index dd49c4cfa4c74..37a9b324773c9 100644 --- a/src/main/java/org/elasticsearch/index/query/NotQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/NotQueryBuilder.java @@ -35,10 +35,19 @@ public class NotQueryBuilder extends QueryBuilder { private String queryName; + static final NotQueryBuilder PROTOTYPE = new NotQueryBuilder(); + public NotQueryBuilder(QueryBuilder filter) { this.filter = Objects.requireNonNull(filter); } + /** + * private constructor for internal use + */ + private NotQueryBuilder() { + this.filter = null; + } + public NotQueryBuilder queryName(String queryName) { this.queryName = queryName; return this; diff --git a/src/main/java/org/elasticsearch/index/query/NotQueryParser.java b/src/main/java/org/elasticsearch/index/query/NotQueryParser.java index 26b932d2bfd2f..c33b947fa4367 100644 --- a/src/main/java/org/elasticsearch/index/query/NotQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/NotQueryParser.java @@ -94,4 +94,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return notQuery; } + + @Override + public NotQueryBuilder getBuilderPrototype() { + return NotQueryBuilder.PROTOTYPE; + } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/query/OrQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/OrQueryBuilder.java index 53c9b968437e2..6f1cd30bd1f26 100644 --- a/src/main/java/org/elasticsearch/index/query/OrQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/OrQueryBuilder.java @@ -40,6 +40,8 @@ public class OrQueryBuilder extends QueryBuilder { private String queryName; + static final OrQueryBuilder PROTOTYPE = new OrQueryBuilder(); + public OrQueryBuilder(QueryBuilder... filters) { Collections.addAll(this.filters, filters); } diff --git a/src/main/java/org/elasticsearch/index/query/OrQueryParser.java b/src/main/java/org/elasticsearch/index/query/OrQueryParser.java index cad0828d5e25d..e328ac8174228 100644 --- a/src/main/java/org/elasticsearch/index/query/OrQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/OrQueryParser.java @@ -112,4 +112,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public OrQueryBuilder getBuilderPrototype() { + return OrQueryBuilder.PROTOTYPE; + } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java index fee8273ded6c1..a048b54a0ac59 100644 --- a/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java @@ -40,6 +40,8 @@ public class PrefixQueryBuilder extends MultiTermQueryBuilder implements Boostab private String queryName; + static final PrefixQueryBuilder PROTOTYPE = new PrefixQueryBuilder(null, null); + /** * A Query that matches documents containing terms with a specified prefix. * diff --git a/src/main/java/org/elasticsearch/index/query/PrefixQueryParser.java b/src/main/java/org/elasticsearch/index/query/PrefixQueryParser.java index 7d34f64953220..7d0cd296ee1cc 100644 --- a/src/main/java/org/elasticsearch/index/query/PrefixQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/PrefixQueryParser.java @@ -115,4 +115,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public PrefixQueryBuilder getBuilderPrototype() { + return PrefixQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/QueryFilterBuilder.java b/src/main/java/org/elasticsearch/index/query/QueryFilterBuilder.java index 715ba39d73a62..bcce639103acd 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryFilterBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/QueryFilterBuilder.java @@ -40,6 +40,8 @@ public class QueryFilterBuilder extends QueryBuilder { private String queryName; + static final QueryFilterBuilder PROTOTYPE = new QueryFilterBuilder(null); + /** * A filter that simply wraps a query. * diff --git a/src/main/java/org/elasticsearch/index/query/QueryFilterParser.java b/src/main/java/org/elasticsearch/index/query/QueryFilterParser.java index a63491f2f04ab..387ae01254c66 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryFilterParser.java +++ b/src/main/java/org/elasticsearch/index/query/QueryFilterParser.java @@ -41,4 +41,9 @@ public String[] names() { public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { return new ConstantScoreQuery(parseContext.parseInnerQuery()); } + + @Override + public QueryFilterBuilder getBuilderPrototype() { + return QueryFilterBuilder.PROTOTYPE; + } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/query/QueryParser.java b/src/main/java/org/elasticsearch/index/query/QueryParser.java index 85f9570773e05..b53fe861e838c 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/QueryParser.java @@ -59,4 +59,9 @@ public interface QueryParser { * @throws QueryParsingException */ QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException; + + /** + * @return an empty {@link QueryBuilder} instance for this parser that can be used for deserialization + */ + QueryBuilder getBuilderPrototype(); } diff --git a/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java index cf7d52ac95a70..58323369c44cf 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java @@ -101,6 +101,8 @@ public enum Operator { /** To limit effort spent determinizing regexp queries. */ private Integer maxDeterminizedStates; + static final QueryStringQueryBuilder PROTOTYPE = new QueryStringQueryBuilder(null); + public QueryStringQueryBuilder(String queryString) { this.queryString = queryString; } diff --git a/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java b/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java index 796862a3ed847..a6c527532f511 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java @@ -245,4 +245,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars throw new QueryParsingException(parseContext, "Failed to parse query [" + qpSettings.queryString() + "]", e); } } + + @Override + public QueryStringQueryBuilder getBuilderPrototype() { + return QueryStringQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java index d8b104f2b475f..9c671fa2edc69 100644 --- a/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java @@ -59,6 +59,8 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder private String format; + static final RangeQueryBuilder PROTOTYPE = new RangeQueryBuilder(null); + /** * A Query that matches documents within an range of terms. * diff --git a/src/main/java/org/elasticsearch/index/query/RangeQueryParser.java b/src/main/java/org/elasticsearch/index/query/RangeQueryParser.java index d6e1cda88a2ad..871bd82af5390 100644 --- a/src/main/java/org/elasticsearch/index/query/RangeQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/RangeQueryParser.java @@ -19,12 +19,9 @@ package org.elasticsearch.index.query; -import org.apache.lucene.search.TermRangeQuery; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.mapper.FieldMapper; -import org.elasticsearch.index.mapper.core.DateFieldMapper; import java.io.IOException; @@ -125,4 +122,9 @@ public RangeQueryBuilder fromXContent(QueryParseContext parseContext) throws IOE rangeQuery.validate(); return rangeQuery; } + + @Override + public RangeQueryBuilder getBuilderPrototype() { + return RangeQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java index c4d94db13a9b7..d273e1bc88ec7 100644 --- a/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java @@ -39,6 +39,7 @@ public class RegexpQueryBuilder extends MultiTermQueryBuilder implements Boostab private String queryName; private int maxDeterminizedStates = Operations.DEFAULT_MAX_DETERMINIZED_STATES; private boolean maxDetermizedStatesSet; + static final RegexpQueryBuilder PROTOTYPE = new RegexpQueryBuilder(null, null); /** * Constructs a new term query. diff --git a/src/main/java/org/elasticsearch/index/query/RegexpQueryParser.java b/src/main/java/org/elasticsearch/index/query/RegexpQueryParser.java index 7a0a1424d0be2..36580a41f8996 100644 --- a/src/main/java/org/elasticsearch/index/query/RegexpQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/RegexpQueryParser.java @@ -124,5 +124,10 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars return query; } + @Override + public RegexpQueryBuilder getBuilderPrototype() { + return RegexpQueryBuilder.PROTOTYPE; + } + } diff --git a/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java index 9a1780801b7b0..41b09eab14b2b 100644 --- a/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java @@ -38,6 +38,8 @@ public class ScriptQueryBuilder extends QueryBuilder { private String queryName; + static final ScriptQueryBuilder PROTOTYPE = new ScriptQueryBuilder(null); + public ScriptQueryBuilder(String script) { this.script = script; } diff --git a/src/main/java/org/elasticsearch/index/query/ScriptQueryParser.java b/src/main/java/org/elasticsearch/index/query/ScriptQueryParser.java index b5835ae625504..3c275db2b3f12 100644 --- a/src/main/java/org/elasticsearch/index/query/ScriptQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/ScriptQueryParser.java @@ -189,4 +189,9 @@ public int length() { }; } } + + @Override + public ScriptQueryBuilder getBuilderPrototype() { + return ScriptQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java b/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java index 14f6edf92c81d..0559a46c5d7ab 100644 --- a/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java @@ -43,6 +43,7 @@ public class SimpleQueryStringBuilder extends QueryBuilder { private Boolean lenient; private Boolean analyzeWildcard; private Locale locale; + static final SimpleQueryStringBuilder PROTOTYPE = new SimpleQueryStringBuilder(null); /** * Operators for the default_operator diff --git a/src/main/java/org/elasticsearch/index/query/SimpleQueryStringParser.java b/src/main/java/org/elasticsearch/index/query/SimpleQueryStringParser.java index 021b32659172d..bca98c517ab75 100644 --- a/src/main/java/org/elasticsearch/index/query/SimpleQueryStringParser.java +++ b/src/main/java/org/elasticsearch/index/query/SimpleQueryStringParser.java @@ -230,4 +230,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public SimpleQueryStringBuilder getBuilderPrototype() { + return SimpleQueryStringBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanContainingQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanContainingQueryBuilder.java index 94ccc47df37f7..e870b33284f3c 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanContainingQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanContainingQueryBuilder.java @@ -33,6 +33,7 @@ public class SpanContainingQueryBuilder extends QueryBuilder implements SpanQuer private SpanQueryBuilder little; private float boost = -1; private String queryName; + static final SpanContainingQueryBuilder PROTOTYPE = new SpanContainingQueryBuilder(); /** * Sets the little clause, it must be contained within {@code big} for a match. diff --git a/src/main/java/org/elasticsearch/index/query/SpanContainingQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanContainingQueryParser.java index bd24d25d05698..fe534dc099ae5 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanContainingQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanContainingQueryParser.java @@ -95,4 +95,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public SpanContainingQueryBuilder getBuilderPrototype() { + return SpanContainingQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanFirstQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanFirstQueryBuilder.java index 1f5bee4c871e6..2b551c0c7d163 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanFirstQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanFirstQueryBuilder.java @@ -35,6 +35,8 @@ public class SpanFirstQueryBuilder extends QueryBuilder implements SpanQueryBuil private String queryName; + static final SpanFirstQueryBuilder SPAN_FIRST_QUERY_BUILDER = new SpanFirstQueryBuilder(null, -1); + public SpanFirstQueryBuilder(SpanQueryBuilder matchBuilder, int end) { this.matchBuilder = matchBuilder; this.end = end; diff --git a/src/main/java/org/elasticsearch/index/query/SpanFirstQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanFirstQueryParser.java index 039b5b0bd4d5f..25b62f60e6f99 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanFirstQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanFirstQueryParser.java @@ -93,4 +93,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public SpanFirstQueryBuilder getBuilderPrototype() { + return SpanFirstQueryBuilder.SPAN_FIRST_QUERY_BUILDER; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryBuilder.java index 36fe9e75b49e9..6fec7732426fc 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryBuilder.java @@ -26,6 +26,7 @@ public class SpanMultiTermQueryBuilder extends QueryBuilder implements SpanQuery public static final String NAME = "span_multi"; private MultiTermQueryBuilder multiTermQueryBuilder; + static final SpanMultiTermQueryBuilder PROTOTYPE = new SpanMultiTermQueryBuilder(null); public SpanMultiTermQueryBuilder(MultiTermQueryBuilder multiTermQueryBuilder) { this.multiTermQueryBuilder = multiTermQueryBuilder; diff --git a/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryParser.java index af786f2f9d8d5..14841cb6df742 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanMultiTermQueryParser.java @@ -66,4 +66,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars parser.nextToken(); return new SpanMultiTermQueryWrapper<>((MultiTermQuery) subQuery); } + + @Override + public SpanMultiTermQueryBuilder getBuilderPrototype() { + return SpanMultiTermQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java index 0cf4d688a4afd..01003a794dc5e 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java @@ -40,6 +40,8 @@ public class SpanNearQueryBuilder extends QueryBuilder implements SpanQueryBuild private String queryName; + static final SpanNearQueryBuilder PROTOTYPE = new SpanNearQueryBuilder(); + public SpanNearQueryBuilder clause(SpanQueryBuilder clause) { clauses.add(clause); return this; diff --git a/src/main/java/org/elasticsearch/index/query/SpanNearQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanNearQueryParser.java index 131d6a3cc35db..4ec0c66bebb5f 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNearQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNearQueryParser.java @@ -106,4 +106,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public SpanNearQueryBuilder getBuilderPrototype() { + return SpanNearQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java index 96af608151969..ce32f7989315e 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java @@ -41,6 +41,8 @@ public class SpanNotQueryBuilder extends QueryBuilder implements SpanQueryBuilde private String queryName; + static final SpanNotQueryBuilder PROTOTYPE = new SpanNotQueryBuilder(); + public SpanNotQueryBuilder include(SpanQueryBuilder include) { this.include = include; return this; diff --git a/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java index a094fe4cf0a8c..a92838c9af9b2 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java @@ -126,4 +126,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public SpanNotQueryBuilder getBuilderPrototype() { + return SpanNotQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java index dd15d3d95bcd8..6329d35b1d615 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java @@ -34,6 +34,8 @@ public class SpanOrQueryBuilder extends QueryBuilder implements SpanQueryBuilder private String queryName; + static final SpanOrQueryBuilder PROTOTYPE = new SpanOrQueryBuilder(); + public SpanOrQueryBuilder clause(SpanQueryBuilder clause) { clauses.add(clause); return this; diff --git a/src/main/java/org/elasticsearch/index/query/SpanOrQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanOrQueryParser.java index 02e95a4876d76..346004bfdf71e 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanOrQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanOrQueryParser.java @@ -92,4 +92,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public SpanOrQueryBuilder getBuilderPrototype() { + return SpanOrQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java index a5b8fae105ecd..564ade46dcae9 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java @@ -33,6 +33,7 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder implements SpanQueryBuilder { public static final String NAME = "span_term"; + static final SpanTermQueryBuilder PROTOTYPE = new SpanTermQueryBuilder(null, null); /** @see BaseTermQueryBuilder#BaseTermQueryBuilder(String, String) */ public SpanTermQueryBuilder(String name, String value) { diff --git a/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java index 1db8025580627..4302d61832d8f 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java @@ -92,4 +92,9 @@ public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOExcept result.validate(); return result; } + + @Override + public SpanTermQueryBuilder getBuilderPrototype() { + return SpanTermQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/SpanWithinQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanWithinQueryBuilder.java index b98bc86286bec..bca469c0a1538 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanWithinQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanWithinQueryBuilder.java @@ -33,6 +33,7 @@ public class SpanWithinQueryBuilder extends QueryBuilder implements SpanQueryBui private SpanQueryBuilder little; private float boost = -1; private String queryName; + static final SpanWithinQueryBuilder PROTOTYPE = new SpanWithinQueryBuilder(); /** * Sets the little clause, it must be contained within {@code big} for a match. diff --git a/src/main/java/org/elasticsearch/index/query/SpanWithinQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanWithinQueryParser.java index 73c4bb653d535..7762c76a96317 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanWithinQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanWithinQueryParser.java @@ -95,4 +95,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public SpanWithinQueryBuilder getBuilderPrototype() { + return SpanWithinQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java index 1e40f0ef83ef1..0ec55907a1e7f 100644 --- a/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java @@ -39,6 +39,8 @@ public class TemplateQueryBuilder extends QueryBuilder { private ScriptService.ScriptType templateType; + static final TemplateQueryBuilder PROTOTYPE = new TemplateQueryBuilder(null, null); + /** * @param template the template to use for that query. * @param vars the parameters to fill the template with. diff --git a/src/main/java/org/elasticsearch/index/query/TemplateQueryParser.java b/src/main/java/org/elasticsearch/index/query/TemplateQueryParser.java index 51dc82cfbe156..d2fbb3140ae66 100644 --- a/src/main/java/org/elasticsearch/index/query/TemplateQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/TemplateQueryParser.java @@ -155,4 +155,9 @@ public String toString(){ return type + " " + template; } } + + @Override + public TemplateQueryBuilder getBuilderPrototype() { + return TemplateQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java index 6bb3cffa8b2bb..54aff40ab3b47 100644 --- a/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java @@ -31,6 +31,7 @@ public class TermQueryBuilder extends BaseTermQueryBuilder implements BoostableQueryBuilder { public static final String NAME = "term"; + static final TermQueryBuilder PROTOTYPE = new TermQueryBuilder(null, null); /** @see BaseTermQueryBuilder#BaseTermQueryBuilder(String, String) */ public TermQueryBuilder(String fieldName, String value) { diff --git a/src/main/java/org/elasticsearch/index/query/TermQueryParser.java b/src/main/java/org/elasticsearch/index/query/TermQueryParser.java index 13da986520e53..31d1a22f4c485 100644 --- a/src/main/java/org/elasticsearch/index/query/TermQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/TermQueryParser.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.query; -import org.apache.lucene.search.TermQuery; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.xcontent.XContentParser; @@ -96,4 +95,9 @@ public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOExcept termQuery.validate(); return termQuery; } + + @Override + public TermQueryBuilder getBuilderPrototype() { + return TermQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java index 908bff80d5644..63fba5aa9d9b1 100644 --- a/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java @@ -45,6 +45,8 @@ public class TermsQueryBuilder extends QueryBuilder { private String lookupPath; private Boolean lookupCache; + static final TermsQueryBuilder PROTOTYPE = new TermsQueryBuilder(null, (Object) null); + /** * A filter for a field based on several terms matching on any of them. * diff --git a/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java b/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java index 4d587b70bd69f..4dfe46f11abde 100644 --- a/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java @@ -207,4 +207,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return query; } + + @Override + public TermsQueryBuilder getBuilderPrototype() { + return TermsQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java index 667ae35b6e8a9..444318fd95b1f 100644 --- a/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java @@ -27,6 +27,7 @@ public class TypeQueryBuilder extends QueryBuilder { public static final String NAME = "type"; private final String type; + static final TypeQueryBuilder PROTOTYPE = new TypeQueryBuilder(null); public TypeQueryBuilder(String type) { this.type = type; diff --git a/src/main/java/org/elasticsearch/index/query/TypeQueryParser.java b/src/main/java/org/elasticsearch/index/query/TypeQueryParser.java index 0f0630ad3fc4d..979a712da6ea9 100644 --- a/src/main/java/org/elasticsearch/index/query/TypeQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/TypeQueryParser.java @@ -62,7 +62,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars parser.nextToken(); Query filter; - //LUCENE 4 UPGRADE document mapper should use bytesref as well? + //LUCENE 4 UPGRADE document mapper should use bytesref as well? DocumentMapper documentMapper = parseContext.mapperService().documentMapper(type.utf8ToString()); if (documentMapper == null) { filter = new TermQuery(new Term(TypeFieldMapper.NAME, type)); @@ -71,4 +71,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return filter; } + + @Override + public TypeQueryBuilder getBuilderPrototype() { + return TypeQueryBuilder.PROTOTYPE; + } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java index 13ab05e04b0ff..2e8a2cb7187ab 100644 --- a/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java @@ -45,6 +45,8 @@ public class WildcardQueryBuilder extends MultiTermQueryBuilder implements Boost private String queryName; + static final WildcardQueryBuilder PROTOTYPE = new WildcardQueryBuilder(null, null); + /** * Implements the wildcard search query. Supported wildcards are *, which * matches any character sequence (including the empty one), and ?, diff --git a/src/main/java/org/elasticsearch/index/query/WildcardQueryParser.java b/src/main/java/org/elasticsearch/index/query/WildcardQueryParser.java index 9dd587b4a345b..7de1fd2836410 100644 --- a/src/main/java/org/elasticsearch/index/query/WildcardQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/WildcardQueryParser.java @@ -108,4 +108,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars } return wildcardQuery; } + + @Override + public WildcardQueryBuilder getBuilderPrototype() { + return WildcardQueryBuilder.PROTOTYPE; + } } diff --git a/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java index 6b8a2c4977be0..1461eb999cacc 100644 --- a/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java @@ -46,6 +46,7 @@ public class WrapperQueryBuilder extends QueryBuilder { private final byte[] source; private final int offset; private final int length; + static final WrapperQueryBuilder PROTOTYPE = new WrapperQueryBuilder(null, -1, -1); /** * Creates a query builder given a query provided as a string diff --git a/src/main/java/org/elasticsearch/index/query/WrapperQueryParser.java b/src/main/java/org/elasticsearch/index/query/WrapperQueryParser.java index 9a1454292b0c6..3d5c0ab063014 100644 --- a/src/main/java/org/elasticsearch/index/query/WrapperQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/WrapperQueryParser.java @@ -64,4 +64,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars return result; } } + + @Override + public WrapperQueryBuilder getBuilderPrototype() { + return WrapperQueryBuilder.PROTOTYPE; + } } 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 9ca5ea4ad54aa..c59ca4056b945 100644 --- a/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java @@ -49,6 +49,8 @@ public class FunctionScoreQueryBuilder extends QueryBuilder implements Boostable private ArrayList scoreFunctions = new ArrayList<>(); private Float minScore = null; + static final FunctionScoreQueryBuilder PROTOTYPE = new FunctionScoreQueryBuilder(); + /** * Creates a function_score query that executes on documents that match query a query. * Query and filter will be wrapped into a filtered_query. 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 86684cada8d56..4c05d4db904aa 100644 --- a/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java @@ -277,4 +277,9 @@ public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOExcept Query query = parse(parseContext); return new QueryWrappingQueryBuilder(query); } + + @Override + public FunctionScoreQueryBuilder getBuilderPrototype() { + return FunctionScoreQueryBuilder.PROTOTYPE; + } } diff --git a/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java b/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java index 28dc0f85bc9c4..f0f1df886eb6e 100644 --- a/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java +++ b/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java @@ -191,6 +191,11 @@ public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOExcept assertEquals(XContentParser.Token.END_OBJECT, parseContext.parser().nextToken()); return new DummyQueryBuilder(); } + + @Override + public DummyQueryBuilder getBuilderPrototype() { + return new DummyQueryBuilder(); + } } private static class DummyQueryBuilder extends QueryBuilder { 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 89c203835fcc7..13e99f3eff1c4 100644 --- a/src/test/java/org/elasticsearch/index/query/guice/MyJsonQueryParser.java +++ b/src/test/java/org/elasticsearch/index/query/guice/MyJsonQueryParser.java @@ -69,4 +69,9 @@ public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOExcept Query query = parse(parseContext); return new QueryWrappingQueryBuilder(query); } + + @Override + public QueryBuilder getBuilderPrototype() { + throw new UnsupportedOperationException("Not implemented in test class"); + } } 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 d67fc7c72cca6..fdf1be4e9f515 100644 --- a/src/test/java/org/elasticsearch/index/query/plugin/PluginJsonQueryParser.java +++ b/src/test/java/org/elasticsearch/index/query/plugin/PluginJsonQueryParser.java @@ -69,4 +69,9 @@ public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOExcept Query query = parse(parseContext); return new QueryWrappingQueryBuilder(query); } + + @Override + public QueryBuilder getBuilderPrototype() { + throw new UnsupportedOperationException("Not implemented in test class"); + } } \ No newline at end of file