From 3197f7f7d856883f66b491270648e532952ad73a Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 13 Apr 2016 14:31:00 -0400 Subject: [PATCH] Remove PROTOTYPE from filter aggregation and cut it to registerAggregation Relates to #17085 --- .../elasticsearch/search/SearchModule.java | 4 +- .../filter/FilterAggregatorBuilder.java | 47 ++++++++++++---- .../bucket/filter/FilterParser.java | 54 ------------------- 3 files changed, 39 insertions(+), 66 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterParser.java diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index e4dc3dedec5..5196ee00583 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -103,7 +103,7 @@ import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.children.InternalChildren; -import org.elasticsearch.search.aggregations.bucket.filter.FilterParser; +import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter; import org.elasticsearch.search.aggregations.bucket.filters.FiltersParser; import org.elasticsearch.search.aggregations.bucket.filters.InternalFilters; @@ -451,7 +451,7 @@ public class SearchModule extends AbstractModule { registerAggregatorParser(new CardinalityParser()); registerAggregatorParser(new GlobalParser()); registerAggregatorParser(new MissingParser()); - registerAggregatorParser(new FilterParser()); + registerAggregation(FilterAggregatorBuilder::new, FilterAggregatorBuilder::parse, FilterAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregatorParser(new FiltersParser(queryParserRegistry)); registerAggregatorParser(new SamplerParser()); registerAggregatorParser(new DiversifiedSamplerParser()); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregatorBuilder.java index fdf94f1529b..494df6fe539 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregatorBuilder.java @@ -19,12 +19,16 @@ package org.elasticsearch.search.aggregations.bucket.filter; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.EmptyQueryBuilder; import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; @@ -34,8 +38,8 @@ import java.io.IOException; import java.util.Objects; public class FilterAggregatorBuilder extends AggregatorBuilder { - - static final FilterAggregatorBuilder PROTOTYPE = new FilterAggregatorBuilder("", new MatchAllQueryBuilder()); + public static final String NAME = InternalFilter.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); private final QueryBuilder filter; @@ -59,6 +63,24 @@ public class FilterAggregatorBuilder extends AggregatorBuilder doBuild(AggregationContext context, AggregatorFactory parent, AggregatorFactories.Builder subFactoriesBuilder) throws IOException { @@ -73,16 +95,17 @@ public class FilterAggregatorBuilder extends AggregatorBuilder filter = context.parseInnerQueryBuilder(); + + if (filter == null) { + throw new ParsingException(null, "filter cannot be null in filter aggregation [{}]", aggregationName); + } + + return new FilterAggregatorBuilder(aggregationName, filter); } - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeQuery(filter); - } @Override protected int doHashCode() { @@ -95,4 +118,8 @@ public class FilterAggregatorBuilder extends AggregatorBuilder filter = context.parseInnerQueryBuilder(); - - if (filter == null) { - throw new ParsingException(null, "filter cannot be null in filter aggregation [{}]", aggregationName); - } - - return new FilterAggregatorBuilder(aggregationName, filter); - } - - @Override - public FilterAggregatorBuilder getFactoryPrototypes() { - return FilterAggregatorBuilder.PROTOTYPE; - } - -}