mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-19 19:35:02 +00:00
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.AggregatorParsers;
|
||||||
import org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregatorBuilder;
|
import org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregatorBuilder;
|
||||||
import org.elasticsearch.search.aggregations.bucket.children.InternalChildren;
|
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.filter.InternalFilter;
|
||||||
import org.elasticsearch.search.aggregations.bucket.filters.FiltersParser;
|
import org.elasticsearch.search.aggregations.bucket.filters.FiltersParser;
|
||||||
import org.elasticsearch.search.aggregations.bucket.filters.InternalFilters;
|
import org.elasticsearch.search.aggregations.bucket.filters.InternalFilters;
|
||||||
@ -451,7 +451,7 @@ public class SearchModule extends AbstractModule {
|
|||||||
registerAggregatorParser(new CardinalityParser());
|
registerAggregatorParser(new CardinalityParser());
|
||||||
registerAggregatorParser(new GlobalParser());
|
registerAggregatorParser(new GlobalParser());
|
||||||
registerAggregatorParser(new MissingParser());
|
registerAggregatorParser(new MissingParser());
|
||||||
registerAggregatorParser(new FilterParser());
|
registerAggregation(FilterAggregatorBuilder::new, FilterAggregatorBuilder::parse, FilterAggregatorBuilder.AGGREGATION_NAME_FIELD);
|
||||||
registerAggregatorParser(new FiltersParser(queryParserRegistry));
|
registerAggregatorParser(new FiltersParser(queryParserRegistry));
|
||||||
registerAggregatorParser(new SamplerParser());
|
registerAggregatorParser(new SamplerParser());
|
||||||
registerAggregatorParser(new DiversifiedSamplerParser());
|
registerAggregatorParser(new DiversifiedSamplerParser());
|
||||||
|
@ -19,12 +19,16 @@
|
|||||||
|
|
||||||
package org.elasticsearch.search.aggregations.bucket.filter;
|
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.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.query.EmptyQueryBuilder;
|
import org.elasticsearch.index.query.EmptyQueryBuilder;
|
||||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
|
import org.elasticsearch.index.query.QueryParseContext;
|
||||||
import org.elasticsearch.search.aggregations.AggregatorBuilder;
|
import org.elasticsearch.search.aggregations.AggregatorBuilder;
|
||||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||||
@ -34,8 +38,8 @@ import java.io.IOException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class FilterAggregatorBuilder extends AggregatorBuilder<FilterAggregatorBuilder> {
|
public class FilterAggregatorBuilder extends AggregatorBuilder<FilterAggregatorBuilder> {
|
||||||
|
public static final String NAME = InternalFilter.TYPE.name();
|
||||||
static final FilterAggregatorBuilder PROTOTYPE = new FilterAggregatorBuilder("", new MatchAllQueryBuilder());
|
public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
|
||||||
|
|
||||||
private final QueryBuilder<?> filter;
|
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
|
@Override
|
||||||
protected AggregatorFactory<?> doBuild(AggregationContext context, AggregatorFactory<?> parent,
|
protected AggregatorFactory<?> doBuild(AggregationContext context, AggregatorFactory<?> parent,
|
||||||
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
|
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
|
||||||
@ -73,16 +95,17 @@ public class FilterAggregatorBuilder extends AggregatorBuilder<FilterAggregatorB
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static FilterAggregatorBuilder parse(String aggregationName, QueryParseContext context)
|
||||||
protected FilterAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException {
|
throws IOException {
|
||||||
FilterAggregatorBuilder factory = new FilterAggregatorBuilder(name, in.readQuery());
|
QueryBuilder<?> filter = context.parseInnerQueryBuilder();
|
||||||
return factory;
|
|
||||||
|
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
|
@Override
|
||||||
protected int doHashCode() {
|
protected int doHashCode() {
|
||||||
@ -95,4 +118,8 @@ public class FilterAggregatorBuilder extends AggregatorBuilder<FilterAggregatorB
|
|||||||
return Objects.equals(filter, other.filter);
|
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…
x
Reference in New Issue
Block a user