Remove PROTOTYPE from filter aggregation
and cut it to registerAggregation Relates to #17085
This commit is contained in:
parent
0c9aca94d4
commit
3197f7f7d8
|
@ -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());
|
||||
|
|
|
@ -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<FilterAggregatorBuilder> {
|
||||
|
||||
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<FilterAggregatorB
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public FilterAggregatorBuilder(StreamInput in) throws IOException {
|
||||
super(in, InternalFilter.TYPE);
|
||||
filter = in.readQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean usesNewStyleSerialization() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AggregatorFactory<?> doBuild(AggregationContext context, AggregatorFactory<?> parent,
|
||||
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
|
||||
|
@ -73,17 +95,18 @@ public class FilterAggregatorBuilder extends AggregatorBuilder<FilterAggregatorB
|
|||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FilterAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException {
|
||||
FilterAggregatorBuilder factory = new FilterAggregatorBuilder(name, in.readQuery());
|
||||
return factory;
|
||||
public static FilterAggregatorBuilder parse(String aggregationName, QueryParseContext context)
|
||||
throws IOException {
|
||||
QueryBuilder<?> filter = context.parseInnerQueryBuilder();
|
||||
|
||||
if (filter == null) {
|
||||
throw new ParsingException(null, "filter cannot be null in filter aggregation [{}]", aggregationName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(filter);
|
||||
return new FilterAggregatorBuilder(aggregationName, filter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(filter);
|
||||
|
@ -95,4 +118,8 @@ public class FilterAggregatorBuilder extends AggregatorBuilder<FilterAggregatorB
|
|||
return Objects.equals(filter, other.filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* 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.search.aggregations.bucket.filter;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class FilterParser implements Aggregator.Parser {
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return InternalFilter.TYPE.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterAggregatorBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
|
||||
QueryBuilder<?> 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue