Makes the AggregatorFactory and PipelineAggregatorFactory setter methods chain able

This commit is contained in:
Colin Goodheart-Smithe 2016-01-08 14:45:58 +00:00
parent 1883317219
commit 7e7e4a2b59
76 changed files with 434 additions and 308 deletions

View File

@ -42,11 +42,12 @@ import java.util.Objects;
/**
* A factory that knows how to create an {@link Aggregator} of a specific type.
*/
public abstract class AggregatorFactory extends ToXContentToBytes implements NamedWriteable<AggregatorFactory> {
public abstract class AggregatorFactory<AF extends AggregatorFactory<AF>> extends ToXContentToBytes
implements NamedWriteable<AggregatorFactory<AF>> {
protected String name;
protected Type type;
protected AggregatorFactory parent;
protected AggregatorFactory<?> parent;
protected AggregatorFactories factories = AggregatorFactories.EMPTY;
protected Map<String, Object> metaData;
private AggregationContext context;
@ -89,10 +90,10 @@ public abstract class AggregatorFactory extends ToXContentToBytes implements Nam
* @param subFactories The sub-factories
* @return this factory (fluent interface)
*/
public AggregatorFactory subFactories(AggregatorFactories subFactories) {
public AF subFactories(AggregatorFactories subFactories) {
this.factories = subFactories;
this.factories.setParent(this);
return this;
return (AF) this;
}
public String name() {
@ -110,7 +111,7 @@ public abstract class AggregatorFactory extends ToXContentToBytes implements Nam
/**
* @return The parent factory if one exists (will always return {@code null} for top level aggregator factories).
*/
public AggregatorFactory parent() {
public AggregatorFactory<?> parent() {
return parent;
}
@ -138,9 +139,9 @@ public abstract class AggregatorFactory extends ToXContentToBytes implements Nam
}
@Override
public final AggregatorFactory readFrom(StreamInput in) throws IOException {
public final AggregatorFactory<AF> readFrom(StreamInput in) throws IOException {
String name = in.readString();
AggregatorFactory factory = doReadFrom(name, in);
AggregatorFactory<AF> factory = doReadFrom(name, in);
factory.factories = AggregatorFactories.EMPTY.readFrom(in);
factory.factories.setParent(this);
factory.metaData = in.readMap();
@ -148,7 +149,7 @@ public abstract class AggregatorFactory extends ToXContentToBytes implements Nam
}
// NORELEASE make this abstract when agg refactor complete
protected AggregatorFactory doReadFrom(String name, StreamInput in) throws IOException {
protected AggregatorFactory<AF> doReadFrom(String name, StreamInput in) throws IOException {
return null;
}
@ -339,7 +340,7 @@ public abstract class AggregatorFactory extends ToXContentToBytes implements Nam
return false;
if (getClass() != obj.getClass())
return false;
AggregatorFactory other = (AggregatorFactory) obj;
AggregatorFactory<AF> other = (AggregatorFactory<AF>) obj;
if (!Objects.equals(name, other.name))
return false;
if (!Objects.equals(type, other.type))

View File

@ -50,7 +50,6 @@ import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.FieldContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.ParentChild;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
@ -190,7 +189,7 @@ public class ParentToChildrenAggregator extends SingleBucketAggregator {
Releasables.close(parentOrdToBuckets, parentOrdToOtherBuckets);
}
public static class Factory extends ValuesSourceAggregatorFactory<ValuesSource.Bytes.WithOrdinals.ParentChild> {
public static class Factory extends ValuesSourceAggregatorFactory<ValuesSource.Bytes.WithOrdinals.ParentChild, Factory> {
private String parentType;
private final String childType;
@ -269,7 +268,7 @@ public class ParentToChildrenAggregator extends SingleBucketAggregator {
}
@Override
protected ValuesSourceAggregatorFactory<ParentChild> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
String childType = in.readString();
Factory factory = new Factory(name, childType);

View File

@ -85,30 +85,23 @@ public class FilterAggregator extends SingleBucketAggregator {
return new InternalFilter(name, 0, buildEmptySubAggregations(), pipelineAggregators(), metaData());
}
public static class Factory extends AggregatorFactory {
public static class Factory extends AggregatorFactory<Factory> {
private QueryBuilder<?> filter;
public Factory(String name) {
/**
* @param name
* the name of this aggregation
* @param filter
* Set the filter to use, only documents that match this
* filter will fall into the bucket defined by this
* {@link Filter} aggregation.
*/
public Factory(String name, QueryBuilder<?> filter) {
super(name, InternalFilter.TYPE);
}
/**
* Set the filter to use, only documents that match this filter will
* fall into the bucket defined by this {@link Filter} aggregation.
*/
public void filter(QueryBuilder<?> filter) {
this.filter = filter;
}
/**
* Get the filter to use, only documents that match this filter will
* fall into the bucket defined by this {@link Filter} aggregation.
*/
public QueryBuilder<?> filter() {
return filter;
}
@Override
public Aggregator createInternal(AggregationContext context, Aggregator parent, boolean collectsFromSingleBucket,
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
@ -125,9 +118,8 @@ public class FilterAggregator extends SingleBucketAggregator {
}
@Override
protected AggregatorFactory doReadFrom(String name, StreamInput in) throws IOException {
Factory factory = new Factory(name);
factory.filter = in.readQuery();
protected Factory doReadFrom(String name, StreamInput in) throws IOException {
Factory factory = new Factory(name, in.readQuery());
return factory;
}

View File

@ -18,12 +18,11 @@
*/
package org.elasticsearch.search.aggregations.bucket.filter;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactory;
@ -34,31 +33,27 @@ import java.io.IOException;
*/
public class FilterParser implements Aggregator.Parser {
private IndicesQueriesRegistry queriesRegistry;
@Inject
public FilterParser(IndicesQueriesRegistry queriesRegistry) {
this.queriesRegistry = queriesRegistry;
}
@Override
public String type() {
return InternalFilter.TYPE.name();
}
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException {
public FilterAggregator.Factory parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException {
QueryBuilder<?> filter = context.parseInnerQueryBuilder();
FilterAggregator.Factory factory = new FilterAggregator.Factory(aggregationName);
factory.filter(filter == null ? new MatchAllQueryBuilder() : filter);
if (filter == null) {
throw new ParsingException(null, "filter cannot be null in filter aggregation [{}]", aggregationName);
}
FilterAggregator.Factory factory = new FilterAggregator.Factory(aggregationName,
filter == null ? new MatchAllQueryBuilder() : filter);
return factory;
}
// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory[] getFactoryPrototypes() {
return new AggregatorFactory[] { new FilterAggregator.Factory(null) };
return new AggregatorFactory[] { new FilterAggregator.Factory(null, null) };
}
}

View File

@ -202,19 +202,31 @@ public class FiltersAggregator extends BucketsAggregator {
return owningBucketOrdinal * totalNumKeys + filterOrd;
}
public static class Factory extends AggregatorFactory {
public static class Factory extends AggregatorFactory<Factory> {
private final List<KeyedFilter> filters;
private final boolean keyed;
private boolean otherBucket = false;
private String otherBucketKey = "_other_";
/**
* @param name
* the name of this aggregation
* @param filters
* the KeyedFilters to use with this aggregation.
*/
public Factory(String name, List<KeyedFilter> filters) {
super(name, InternalFilters.TYPE);
this.filters = filters;
this.keyed = true;
}
/**
* @param name
* the name of this aggregation
* @param filters
* the filters to use with this aggregation
*/
public Factory(String name, QueryBuilder<?>... filters) {
super(name, InternalFilters.TYPE);
List<KeyedFilter> keyedFilters = new ArrayList<>(filters.length);
@ -228,8 +240,9 @@ public class FiltersAggregator extends BucketsAggregator {
/**
* Set whether to include a bucket for documents not matching any filter
*/
public void otherBucket(boolean otherBucket) {
public Factory otherBucket(boolean otherBucket) {
this.otherBucket = otherBucket;
return this;
}
/**
@ -243,8 +256,9 @@ public class FiltersAggregator extends BucketsAggregator {
* Set the key to use for the bucket for documents not matching any
* filter.
*/
public void otherBucketKey(String otherBucketKey) {
public Factory otherBucketKey(String otherBucketKey) {
this.otherBucketKey = otherBucketKey;
return this;
}
/**
@ -285,7 +299,7 @@ public class FiltersAggregator extends BucketsAggregator {
}
@Override
protected AggregatorFactory doReadFrom(String name, StreamInput in) throws IOException {
protected Factory doReadFrom(String name, StreamInput in) throws IOException {
Factory factory;
if (in.readBoolean()) {
int size = in.readVInt();

View File

@ -77,7 +77,7 @@ public class GeoHashGridParser extends GeoPointValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<org.elasticsearch.search.aggregations.support.ValuesSource.GeoPoint> createFactory(
protected GeoGridFactory createFactory(
String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
GeoGridFactory factory = new GeoGridFactory(aggregationName);
@ -114,7 +114,7 @@ public class GeoHashGridParser extends GeoPointValuesSourceParser {
return false;
}
public static class GeoGridFactory extends ValuesSourceAggregatorFactory<ValuesSource.GeoPoint> {
public static class GeoGridFactory extends ValuesSourceAggregatorFactory<ValuesSource.GeoPoint, GeoGridFactory> {
private int precision = DEFAULT_PRECISION;
private int requiredSize = DEFAULT_MAX_NUM_CELLS;
@ -124,16 +124,31 @@ public class GeoHashGridParser extends GeoPointValuesSourceParser {
super(name, InternalGeoHashGrid.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT);
}
public void precision(int precision) {
public GeoGridFactory precision(int precision) {
this.precision = GeoHashGridParams.checkPrecision(precision);
return this;
}
public void size(int size) {
public int precision() {
return precision;
}
public GeoGridFactory size(int size) {
this.requiredSize = size;
return this;
}
public void shardSize(int shardSize) {
public int size() {
return requiredSize;
}
public GeoGridFactory shardSize(int shardSize) {
this.shardSize = shardSize;
return this;
}
public int shardSize() {
return shardSize;
}
@Override
@ -180,7 +195,7 @@ public class GeoHashGridParser extends GeoPointValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<org.elasticsearch.search.aggregations.support.ValuesSource.GeoPoint> innerReadFrom(
protected GeoGridFactory innerReadFrom(
String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
GeoGridFactory factory = new GeoGridFactory(name);

View File

@ -71,7 +71,7 @@ public class GlobalAggregator extends SingleBucketAggregator {
throw new UnsupportedOperationException("global aggregations cannot serve as sub-aggregations, hence should never be called on #buildEmptyAggregations");
}
public static class Factory extends AggregatorFactory {
public static class Factory extends AggregatorFactory<Factory> {
public Factory(String name) {
super(name, InternalGlobal.TYPE);
@ -91,7 +91,7 @@ public class GlobalAggregator extends SingleBucketAggregator {
}
@Override
protected AggregatorFactory doReadFrom(String name, StreamInput in) throws IOException {
protected Factory doReadFrom(String name, StreamInput in) throws IOException {
return new Factory(name);
}

View File

@ -23,9 +23,8 @@ import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.rounding.Rounding;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator.DateHistogramFactory;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -51,7 +50,7 @@ public class DateHistogramParser extends HistogramParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected DateHistogramFactory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
HistogramAggregator.DateHistogramFactory factory = new HistogramAggregator.DateHistogramFactory(aggregationName);
Object interval = otherOptions.get(Rounding.Interval.INTERVAL_FIELD);

View File

@ -162,7 +162,7 @@ public class HistogramAggregator extends BucketsAggregator {
Releasables.close(bucketOrds);
}
public static class Factory extends ValuesSourceAggregatorFactory<ValuesSource.Numeric> {
public static class Factory<AF extends Factory<AF>> extends ValuesSourceAggregatorFactory<ValuesSource.Numeric, Factory<AF>> {
public static final Factory PROTOTYPE = new Factory("");
@ -187,48 +187,54 @@ public class HistogramAggregator extends BucketsAggregator {
return interval;
}
public void interval(long interval) {
public AF interval(long interval) {
this.interval = interval;
return (AF) this;
}
public long offset() {
return offset;
}
public void offset(long offset) {
public AF offset(long offset) {
this.offset = offset;
return (AF) this;
}
public Histogram.Order order() {
return order;
}
public void order(Histogram.Order order) {
public AF order(Histogram.Order order) {
this.order = (InternalOrder) order;
return (AF) this;
}
public boolean keyed() {
return keyed;
}
public void keyed(boolean keyed) {
public AF keyed(boolean keyed) {
this.keyed = keyed;
return (AF) this;
}
public long minDocCount() {
return minDocCount;
}
public void minDocCount(long minDocCount) {
public AF minDocCount(long minDocCount) {
this.minDocCount = minDocCount;
return (AF) this;
}
public ExtendedBounds extendedBounds() {
return extendedBounds;
}
public void extendedBounds(ExtendedBounds extendedBounds) {
public AF extendedBounds(ExtendedBounds extendedBounds) {
this.extendedBounds = extendedBounds;
return (AF) this;
}
public InternalHistogram.Factory<?> getHistogramFactory() {
@ -305,9 +311,9 @@ public class HistogramAggregator extends BucketsAggregator {
}
@Override
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in)
protected AF innerReadFrom(String name, ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in)
throws IOException {
Factory factory = createFactoryFromStream(name, in);
Factory<AF> factory = createFactoryFromStream(name, in);
factory.interval = in.readVLong();
factory.offset = in.readVLong();
if (in.readBoolean()) {
@ -318,12 +324,12 @@ public class HistogramAggregator extends BucketsAggregator {
if (in.readBoolean()) {
factory.extendedBounds = ExtendedBounds.readFrom(in);
}
return factory;
return (AF) factory;
}
protected Factory createFactoryFromStream(String name, StreamInput in)
protected Factory<AF> createFactoryFromStream(String name, StreamInput in)
throws IOException {
return new Factory(name);
return new Factory<AF>(name);
}
@Override
@ -367,7 +373,7 @@ public class HistogramAggregator extends BucketsAggregator {
}
}
public static class DateHistogramFactory extends Factory {
public static class DateHistogramFactory extends Factory<DateHistogramFactory> {
public static final DateHistogramFactory PROTOTYPE = new DateHistogramFactory("");
public static final Map<String, DateTimeUnit> DATE_FIELD_UNITS;
@ -402,8 +408,9 @@ public class HistogramAggregator extends BucketsAggregator {
/**
* Set the interval.
*/
public void dateHistogramInterval(DateHistogramInterval dateHistogramInterval) {
public DateHistogramFactory dateHistogramInterval(DateHistogramInterval dateHistogramInterval) {
this.dateHistogramInterval = dateHistogramInterval;
return this;
}
public DateHistogramInterval dateHistogramInterval() {
@ -448,7 +455,7 @@ public class HistogramAggregator extends BucketsAggregator {
}
@Override
protected Factory createFactoryFromStream(String name, StreamInput in)
protected DateHistogramFactory createFactoryFromStream(String name, StreamInput in)
throws IOException {
DateHistogramFactory factory = new DateHistogramFactory(name);
if (in.readBoolean()) {

View File

@ -27,8 +27,6 @@ import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -53,7 +51,7 @@ public class HistogramParser extends NumericValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected HistogramAggregator.Factory<?> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
HistogramAggregator.Factory factory = new HistogramAggregator.Factory(aggregationName);
Long interval = (Long) otherOptions.get(Rounding.Interval.INTERVAL_FIELD);

View File

@ -29,7 +29,6 @@ import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.LeafBucketCollector;
import org.elasticsearch.search.aggregations.LeafBucketCollectorBase;
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator;
import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
@ -86,7 +85,7 @@ public class MissingAggregator extends SingleBucketAggregator {
return new InternalMissing(name, 0, buildEmptySubAggregations(), pipelineAggregators(), metaData());
}
public static class Factory<VS extends ValuesSource> extends ValuesSourceAggregatorFactory<VS> {
public static class Factory<VS extends ValuesSource> extends ValuesSourceAggregatorFactory<VS, Factory<VS>> {
public Factory(String name, ValuesSourceType valuesSourceType, ValueType valueType) {
super(name, InternalMissing.TYPE, valuesSourceType, valueType);
@ -105,9 +104,9 @@ public class MissingAggregator extends SingleBucketAggregator {
}
@Override
protected ValuesSourceAggregatorFactory<VS> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory<VS> innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) {
return new ValueCountAggregator.Factory<VS>(name, valuesSourceType, targetValueType);
return new Factory<VS>(name, valuesSourceType, targetValueType);
}
@Override

View File

@ -25,7 +25,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.AnyValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -49,7 +48,7 @@ public class MissingParser extends AnyValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected MissingAggregator.Factory<ValuesSource> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
return new MissingAggregator.Factory<ValuesSource>(aggregationName, valuesSourceType, targetValueType);
}

View File

@ -150,7 +150,7 @@ public class NestedAggregator extends SingleBucketAggregator {
return null;
}
public static class Factory extends AggregatorFactory {
public static class Factory extends AggregatorFactory<Factory> {
private final String path;

View File

@ -125,7 +125,7 @@ public class ReverseNestedAggregator extends SingleBucketAggregator {
return parentFilter;
}
public static class Factory extends AggregatorFactory {
public static class Factory extends AggregatorFactory<Factory> {
private String path;
@ -138,8 +138,9 @@ public class ReverseNestedAggregator extends SingleBucketAggregator {
* the path to a nested object in the mappings. If it is not specified
* then this aggregation will go back to the root document.
*/
public void path(String path) {
public Factory path(String path) {
this.path = path;
return this;
}
/**

View File

@ -41,7 +41,6 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.search.aggregations.support.format.ValueFormat;
@ -397,7 +396,7 @@ public class RangeAggregator extends BucketsAggregator {
}
}
public static class Factory extends ValuesSourceAggregatorFactory<ValuesSource.Numeric> {
public static class Factory<AF extends Factory<AF>> extends ValuesSourceAggregatorFactory<ValuesSource.Numeric, AF> {
private final InternalRange.Factory rangeFactory;
private final List<? extends Range> ranges;
@ -413,8 +412,9 @@ public class RangeAggregator extends BucketsAggregator {
this.ranges = ranges;
}
public void keyed(boolean keyed) {
public AF keyed(boolean keyed) {
this.keyed = keyed;
return (AF) this;
}
public boolean keyed() {
@ -441,20 +441,20 @@ public class RangeAggregator extends BucketsAggregator {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected AF innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
Factory factory = createFactoryFromStream(name, in);
Factory<AF> factory = createFactoryFromStream(name, in);
factory.keyed = in.readBoolean();
return factory;
return (AF) factory;
}
protected Factory createFactoryFromStream(String name, StreamInput in) throws IOException {
protected Factory<AF> createFactoryFromStream(String name, StreamInput in) throws IOException {
int size = in.readVInt();
List<Range> ranges = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
ranges.add(Range.PROTOTYPE.readFrom(in));
}
return new Factory(name, ranges);
return new Factory<AF>(name, ranges);
}
@Override

View File

@ -26,8 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -55,7 +53,7 @@ public class RangeParser extends NumericValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected RangeAggregator.Factory<?> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
List<? extends Range> ranges = (List<? extends Range>) otherOptions.get(RangeAggregator.RANGES_FIELD);
RangeAggregator.Factory factory = new RangeAggregator.Factory(aggregationName, ranges);

View File

@ -27,7 +27,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class DateRangeAggregatorFactory extends Factory {
public class DateRangeAggregatorFactory extends Factory<DateRangeAggregatorFactory> {
public DateRangeAggregatorFactory(String name, List<Range> ranges) {
super(name, InternalDateRange.FACTORY, ranges);

View File

@ -24,8 +24,6 @@ import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator;
import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range;
import org.elasticsearch.search.aggregations.bucket.range.RangeParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.util.Collections;
@ -47,7 +45,7 @@ public class DateRangeParser extends RangeParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected DateRangeAggregatorFactory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
List<Range> ranges = (List<Range>) otherOptions.get(RangeAggregator.RANGES_FIELD);
DateRangeAggregatorFactory factory = new DateRangeAggregatorFactory(aggregationName, ranges);

View File

@ -112,7 +112,7 @@ public class GeoDistanceParser extends GeoPointValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<org.elasticsearch.search.aggregations.support.ValuesSource.GeoPoint> createFactory(
protected GeoDistanceFactory createFactory(
String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map<ParseField, Object> otherOptions) {
GeoPoint origin = (GeoPoint) otherOptions.get(ORIGIN_FIELD);
List<Range> ranges = (List<Range>) otherOptions.get(RangeAggregator.RANGES_FIELD);
@ -195,7 +195,7 @@ public class GeoDistanceParser extends GeoPointValuesSourceParser {
return false;
}
public static class GeoDistanceFactory extends ValuesSourceAggregatorFactory<ValuesSource.GeoPoint> {
public static class GeoDistanceFactory extends ValuesSourceAggregatorFactory<ValuesSource.GeoPoint, GeoDistanceFactory> {
private final GeoPoint origin;
private final InternalRange.Factory rangeFactory;
@ -220,24 +220,27 @@ public class GeoDistanceParser extends GeoPointValuesSourceParser {
return InternalGeoDistance.TYPE.name();
}
public void unit(DistanceUnit unit) {
public GeoDistanceFactory unit(DistanceUnit unit) {
this.unit = unit;
return this;
}
public DistanceUnit unit() {
return unit;
}
public void distanceType(GeoDistance distanceType) {
public GeoDistanceFactory distanceType(GeoDistance distanceType) {
this.distanceType = distanceType;
return this;
}
public GeoDistance distanceType() {
return distanceType;
}
public void keyed(boolean keyed) {
public GeoDistanceFactory keyed(boolean keyed) {
this.keyed = keyed;
return this;
}
public boolean keyed() {
@ -273,7 +276,7 @@ public class GeoDistanceParser extends GeoPointValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<org.elasticsearch.search.aggregations.support.ValuesSource.GeoPoint> innerReadFrom(
protected GeoDistanceFactory innerReadFrom(
String name, ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in) throws IOException {
GeoPoint origin = new GeoPoint(in.readDouble(), in.readDouble());
int size = in.readVInt();

View File

@ -34,7 +34,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class IPv4RangeAggregatorFactory extends Factory {
public class IPv4RangeAggregatorFactory extends Factory<IPv4RangeAggregatorFactory> {
public IPv4RangeAggregatorFactory(String name, List<Range> ranges) {
super(name, InternalIPv4Range.FACTORY, ranges);

View File

@ -26,8 +26,6 @@ import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator;
import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range;
import org.elasticsearch.search.aggregations.bucket.range.RangeParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -55,7 +53,7 @@ public class IpRangeParser extends RangeParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected IPv4RangeAggregatorFactory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
List<IPv4RangeAggregatorFactory.Range> ranges = (List<IPv4RangeAggregatorFactory.Range>) otherOptions
.get(RangeAggregator.RANGES_FIELD);

View File

@ -25,8 +25,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.AnyValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -47,7 +45,7 @@ public class DiversifiedSamplerParser extends AnyValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected SamplerAggregator.DiversifiedFactory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
SamplerAggregator.DiversifiedFactory factory = new SamplerAggregator.DiversifiedFactory(aggregationName, valuesSourceType,
targetValueType);

View File

@ -190,7 +190,7 @@ public class SamplerAggregator extends SingleBucketAggregator {
return new InternalSampler(name, 0, buildEmptySubAggregations(), pipelineAggregators(), metaData());
}
public static class Factory extends AggregatorFactory {
public static class Factory extends AggregatorFactory<Factory> {
public static final int DEFAULT_SHARD_SAMPLE_SIZE = 100;
@ -203,8 +203,9 @@ public class SamplerAggregator extends SingleBucketAggregator {
/**
* Set the max num docs to be returned from each shard.
*/
public void shardSize(int shardSize) {
public Factory shardSize(int shardSize) {
this.shardSize = shardSize;
return this;
}
/**
@ -253,7 +254,7 @@ public class SamplerAggregator extends SingleBucketAggregator {
}
public static class DiversifiedFactory extends ValuesSourceAggregatorFactory<ValuesSource> {
public static class DiversifiedFactory extends ValuesSourceAggregatorFactory<ValuesSource, DiversifiedFactory> {
public static final Type TYPE = new Type("diversified_sampler");
@ -270,8 +271,9 @@ public class SamplerAggregator extends SingleBucketAggregator {
/**
* Set the max num docs to be returned from each shard.
*/
public void shardSize(int shardSize) {
public DiversifiedFactory shardSize(int shardSize) {
this.shardSize = shardSize;
return this;
}
/**
@ -284,8 +286,9 @@ public class SamplerAggregator extends SingleBucketAggregator {
/**
* Set the max num docs to be returned per value.
*/
public void maxDocsPerValue(int maxDocsPerValue) {
public DiversifiedFactory maxDocsPerValue(int maxDocsPerValue) {
this.maxDocsPerValue = maxDocsPerValue;
return this;
}
/**
@ -298,8 +301,9 @@ public class SamplerAggregator extends SingleBucketAggregator {
/**
* Set the execution hint.
*/
public void executionHint(String executionHint) {
public DiversifiedFactory executionHint(String executionHint) {
this.executionHint = executionHint;
return this;
}
/**
@ -366,7 +370,7 @@ public class SamplerAggregator extends SingleBucketAggregator {
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected DiversifiedFactory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
DiversifiedFactory factory = new DiversifiedFactory(name, valuesSourceType, targetValueType);
factory.shardSize = in.readVInt();

View File

@ -63,7 +63,8 @@ import java.util.Objects;
/**
*
*/
public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFactory<ValuesSource> implements Releasable {
public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFactory<ValuesSource, SignificantTermsAggregatorFactory>
implements Releasable {
static final ParseField BACKGROUND_FILTER = new ParseField("background_filter");
static final ParseField HEURISTIC = new ParseField("significance_heuristic");
@ -168,15 +169,17 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac
return bucketCountThresholds;
}
public void bucketCountThresholds(TermsAggregator.BucketCountThresholds bucketCountThresholds) {
public SignificantTermsAggregatorFactory bucketCountThresholds(TermsAggregator.BucketCountThresholds bucketCountThresholds) {
this.bucketCountThresholds = bucketCountThresholds;
return this;
}
/**
* Expert: sets an execution hint to the aggregation.
*/
public void executionHint(String executionHint) {
public SignificantTermsAggregatorFactory executionHint(String executionHint) {
this.executionHint = executionHint;
return this;
}
/**
@ -186,8 +189,9 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac
return executionHint;
}
public void backgroundFilter(QueryBuilder<?> filterBuilder) {
public SignificantTermsAggregatorFactory backgroundFilter(QueryBuilder<?> filterBuilder) {
this.filterBuilder = filterBuilder;
return this;
}
public QueryBuilder<?> backgroundFilter() {
@ -197,8 +201,9 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac
/**
* Set terms to include and exclude from the aggregation results
*/
public void includeExclude(IncludeExclude includeExclude) {
public SignificantTermsAggregatorFactory includeExclude(IncludeExclude includeExclude) {
this.includeExclude = includeExclude;
return this;
}
/**
@ -208,8 +213,9 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac
return includeExclude;
}
public void significanceHeuristic(SignificanceHeuristic significanceHeuristic) {
public SignificantTermsAggregatorFactory significanceHeuristic(SignificanceHeuristic significanceHeuristic) {
this.significanceHeuristic = significanceHeuristic;
return this;
}
public SignificanceHeuristic significanceHeuristic() {
@ -391,7 +397,7 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected SignificantTermsAggregatorFactory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
SignificantTermsAggregatorFactory factory = new SignificantTermsAggregatorFactory(name, valuesSourceType, targetValueType);
factory.bucketCountThresholds = BucketCountThresholds.readFromStream(in);

View File

@ -36,8 +36,6 @@ import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregator;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregator.BucketCountThresholds;
import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -63,7 +61,7 @@ public class SignificantTermsParser extends AbstractTermsParser {
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> doCreateFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected SignificantTermsAggregatorFactory doCreateFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, BucketCountThresholds bucketCountThresholds, SubAggCollectionMode collectMode, String executionHint,
IncludeExclude incExc, Map<ParseField, Object> otherOptions) {
SignificantTermsAggregatorFactory factory = new SignificantTermsAggregatorFactory(aggregationName, valuesSourceType,

View File

@ -50,7 +50,7 @@ public abstract class AbstractTermsParser extends AnyValuesSourceParser {
}
@Override
protected final ValuesSourceAggregatorFactory<ValuesSource> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected final ValuesSourceAggregatorFactory<ValuesSource, ?> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
BucketCountThresholds bucketCountThresholds = getDefaultBucketCountThresholds();
Integer requiredSize = (Integer) otherOptions.get(REQUIRED_SIZE_FIELD_NAME);
@ -77,7 +77,7 @@ public abstract class AbstractTermsParser extends AnyValuesSourceParser {
otherOptions);
}
protected abstract ValuesSourceAggregatorFactory<ValuesSource> doCreateFactory(String aggregationName,
protected abstract ValuesSourceAggregatorFactory<ValuesSource, ?> doCreateFactory(String aggregationName,
ValuesSourceType valuesSourceType,
ValueType targetValueType, BucketCountThresholds bucketCountThresholds, SubAggCollectionMode collectMode, String executionHint,
IncludeExclude incExc, Map<ParseField, Object> otherOptions);

View File

@ -54,7 +54,7 @@ import java.util.Objects;
/**
*
*/
public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<ValuesSource> {
public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<ValuesSource, TermsAggregatorFactory> {
public static final ParseField EXECUTION_HINT_FIELD_NAME = new ParseField("execution_hint");
public static final ParseField SHARD_SIZE_FIELD_NAME = new ParseField("shard_size");
@ -198,15 +198,17 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<Values
return bucketCountThresholds;
}
public void bucketCountThresholds(TermsAggregator.BucketCountThresholds bucketCountThresholds) {
public TermsAggregatorFactory bucketCountThresholds(TermsAggregator.BucketCountThresholds bucketCountThresholds) {
this.bucketCountThresholds = bucketCountThresholds;
return this;
}
/**
* Sets the order in which the buckets will be returned.
*/
public void order(List<Terms.Order> order) {
public TermsAggregatorFactory order(List<Terms.Order> order) {
this.orders = order;
return this;
}
/**
@ -219,8 +221,9 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<Values
/**
* Expert: sets an execution hint to the aggregation.
*/
public void executionHint(String executionHint) {
public TermsAggregatorFactory executionHint(String executionHint) {
this.executionHint = executionHint;
return this;
}
/**
@ -233,8 +236,9 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<Values
/**
* Expert: set the collection mode.
*/
public void collectMode(SubAggCollectionMode mode) {
public TermsAggregatorFactory collectMode(SubAggCollectionMode mode) {
this.collectMode = mode;
return this;
}
/**
@ -247,8 +251,9 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<Values
/**
* Set terms to include and exclude from the aggregation results
*/
public void includeExclude(IncludeExclude includeExclude) {
public TermsAggregatorFactory includeExclude(IncludeExclude includeExclude) {
this.includeExclude = includeExclude;
return this;
}
/**
@ -268,8 +273,9 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<Values
/**
* Set whether doc count error will be return for individual terms
*/
public void showTermDocCountError(boolean showTermDocCountError) {
public TermsAggregatorFactory showTermDocCountError(boolean showTermDocCountError) {
this.showTermDocCountError = showTermDocCountError;
return this;
}
@Override
@ -422,7 +428,7 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<Values
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected TermsAggregatorFactory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
TermsAggregatorFactory factory = new TermsAggregatorFactory(name, valuesSourceType, targetValueType);
factory.bucketCountThresholds = BucketCountThresholds.readFromStream(in);

View File

@ -29,8 +29,6 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms.Order;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregator.BucketCountThresholds;
import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -51,7 +49,7 @@ public class TermsParser extends AbstractTermsParser {
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> doCreateFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected TermsAggregatorFactory doCreateFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, BucketCountThresholds bucketCountThresholds, SubAggCollectionMode collectMode, String executionHint,
IncludeExclude incExc, Map<ParseField, Object> otherOptions) {
TermsAggregatorFactory factory = new TermsAggregatorFactory(aggregationName, valuesSourceType, targetValueType);

View File

@ -36,7 +36,6 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
@ -118,7 +117,7 @@ public class AvgAggregator extends NumericMetricsAggregator.SingleValue {
return new InternalAvg(name, 0.0, 0l, formatter, pipelineAggregators(), metaData());
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, Factory> {
public Factory(String name) {
super(name, InternalAvg.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
@ -139,7 +138,7 @@ public class AvgAggregator extends NumericMetricsAggregator.SingleValue {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) {
return new AvgAggregator.Factory(name);
}

View File

@ -24,8 +24,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -52,7 +50,7 @@ public class AvgParser extends NumericValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected AvgAggregator.Factory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
return new AvgAggregator.Factory(aggregationName);
}

View File

@ -37,7 +37,8 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
public final class CardinalityAggregatorFactory<VS extends ValuesSource> extends ValuesSourceAggregatorFactory.LeafOnly<VS> {
public final class CardinalityAggregatorFactory<VS extends ValuesSource>
extends ValuesSourceAggregatorFactory.LeafOnly<VS, CardinalityAggregatorFactory<VS>> {
public static final ParseField PRECISION_THRESHOLD_FIELD = new ParseField("precision_threshold");
@ -51,8 +52,9 @@ public final class CardinalityAggregatorFactory<VS extends ValuesSource> extends
* Set a precision threshold. Higher values improve accuracy but also
* increase memory usage.
*/
public void precisionThreshold(long precisionThreshold) {
public CardinalityAggregatorFactory<VS> precisionThreshold(long precisionThreshold) {
this.precisionThreshold = precisionThreshold;
return this;
}
/**
@ -90,7 +92,7 @@ public final class CardinalityAggregatorFactory<VS extends ValuesSource> extends
}
@Override
protected ValuesSourceAggregatorFactory<VS> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected CardinalityAggregatorFactory<VS> innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
CardinalityAggregatorFactory<VS> factory = new CardinalityAggregatorFactory<>(name, valuesSourceType, targetValueType);
if (in.readBoolean()) {

View File

@ -27,7 +27,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.AnyValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -48,7 +47,7 @@ public class CardinalityParser extends AnyValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected CardinalityAggregatorFactory<ValuesSource> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
CardinalityAggregatorFactory<ValuesSource> factory = new CardinalityAggregatorFactory<>(aggregationName, valuesSourceType,
targetValueType);

View File

@ -174,7 +174,7 @@ public final class GeoBoundsAggregator extends MetricsAggregator {
Releasables.close(tops, bottoms, posLefts, posRights, negLefts, negRights);
}
public static class Factory extends ValuesSourceAggregatorFactory<ValuesSource.GeoPoint> {
public static class Factory extends ValuesSourceAggregatorFactory<ValuesSource.GeoPoint, Factory> {
private boolean wrapLongitude = true;
@ -185,8 +185,9 @@ public final class GeoBoundsAggregator extends MetricsAggregator {
/**
* Set whether to wrap longitudes. Defaults to true.
*/
public void wrapLongitude(boolean wrapLongitude) {
public Factory wrapLongitude(boolean wrapLongitude) {
this.wrapLongitude = wrapLongitude;
return this;
}
/**
@ -210,7 +211,7 @@ public final class GeoBoundsAggregator extends MetricsAggregator {
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource.GeoPoint> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
Factory factory = new Factory(name);
factory.wrapLongitude = in.readBoolean();

View File

@ -26,8 +26,6 @@ import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.GeoPointValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.GeoPoint;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -45,7 +43,7 @@ public class GeoBoundsParser extends GeoPointValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<GeoPoint> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected GeoBoundsAggregator.Factory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
GeoBoundsAggregator.Factory factory = new GeoBoundsAggregator.Factory(aggregationName);
Boolean wrapLongitude = (Boolean) otherOptions.get(GeoBoundsAggregator.WRAP_LONGITUDE_FIELD);

View File

@ -125,7 +125,7 @@ public final class GeoCentroidAggregator extends MetricsAggregator {
Releasables.close(centroids, counts);
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.GeoPoint> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.GeoPoint, Factory> {
public Factory(String name) {
super(name, InternalGeoCentroid.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT);
@ -145,7 +145,7 @@ public final class GeoCentroidAggregator extends MetricsAggregator {
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource.GeoPoint> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
return new Factory(name);
}

View File

@ -26,8 +26,6 @@ import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.GeoPointValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.GeoPoint;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -54,7 +52,7 @@ public class GeoCentroidParser extends GeoPointValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<GeoPoint> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected GeoCentroidAggregator.Factory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
return new GeoCentroidAggregator.Factory(aggregationName);
}

View File

@ -37,7 +37,6 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
@ -119,7 +118,7 @@ public class MaxAggregator extends NumericMetricsAggregator.SingleValue {
return new InternalMax(name, Double.NEGATIVE_INFINITY, formatter, pipelineAggregators(), metaData());
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, Factory> {
public Factory(String name) {
super(name, InternalMax.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
@ -139,7 +138,7 @@ public class MaxAggregator extends NumericMetricsAggregator.SingleValue {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) {
return new MaxAggregator.Factory(name);
}

View File

@ -24,8 +24,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -52,7 +50,7 @@ public class MaxParser extends NumericValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected MaxAggregator.Factory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
return new MaxAggregator.Factory(aggregationName);
}

View File

@ -37,7 +37,6 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
@ -118,7 +117,7 @@ public class MinAggregator extends NumericMetricsAggregator.SingleValue {
return new InternalMin(name, Double.POSITIVE_INFINITY, formatter, pipelineAggregators(), metaData());
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, Factory> {
public Factory(String name) {
super(name, InternalMin.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
@ -138,7 +137,7 @@ public class MinAggregator extends NumericMetricsAggregator.SingleValue {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) {
return new MinAggregator.Factory(name);
}

View File

@ -25,8 +25,6 @@ import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -53,7 +51,7 @@ public class MinParser extends NumericValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected MinAggregator.Factory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
return new MinAggregator.Factory(aggregationName);
}

View File

@ -117,7 +117,7 @@ public abstract class AbstractPercentilesParser extends NumericValuesSourceParse
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected ValuesSourceAggregatorFactory<Numeric, ?> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
PercentilesMethod method = (PercentilesMethod) otherOptions.getOrDefault(METHOD_FIELD, PercentilesMethod.TDIGEST);
@ -128,7 +128,7 @@ public abstract class AbstractPercentilesParser extends NumericValuesSourceParse
return buildFactory(aggregationName, cdfValues, method, compression, numberOfSignificantValueDigits, keyed);
}
protected abstract ValuesSourceAggregatorFactory<Numeric> buildFactory(String aggregationName, double[] cdfValues,
protected abstract ValuesSourceAggregatorFactory<Numeric, ?> buildFactory(String aggregationName, double[] cdfValues,
PercentilesMethod method,
Double compression,
Integer numberOfSignificantValueDigits, Boolean keyed);

View File

@ -48,7 +48,7 @@ public class PercentileRanksParser extends AbstractPercentilesParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> buildFactory(String aggregationName, double[] keys, PercentilesMethod method,
protected ValuesSourceAggregatorFactory<Numeric, ?> buildFactory(String aggregationName, double[] keys, PercentilesMethod method,
Double compression, Integer numberOfSignificantValueDigits, Boolean keyed) {
if (method == PercentilesMethod.TDIGEST) {
TDigestPercentileRanksAggregator.Factory factory = new TDigestPercentileRanksAggregator.Factory(aggregationName);

View File

@ -50,7 +50,7 @@ public class PercentilesParser extends AbstractPercentilesParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> buildFactory(String aggregationName, double[] keys, PercentilesMethod method,
protected ValuesSourceAggregatorFactory<Numeric, ?> buildFactory(String aggregationName, double[] keys, PercentilesMethod method,
Double compression, Integer numberOfSignificantValueDigits, Boolean keyed) {
if (method == PercentilesMethod.TDIGEST) {
TDigestPercentilesAggregator.Factory factory = new TDigestPercentilesAggregator.Factory(aggregationName);

View File

@ -83,7 +83,7 @@ public class HDRPercentileRanksAggregator extends AbstractHDRPercentilesAggregat
}
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, Factory> {
private double[] values;
private int numberOfSignificantValueDigits = 3;
@ -96,10 +96,11 @@ public class HDRPercentileRanksAggregator extends AbstractHDRPercentilesAggregat
/**
* Set the values to compute percentiles from.
*/
public void values(double[] values) {
public Factory values(double[] values) {
double[] sortedValues = Arrays.copyOf(values, values.length);
Arrays.sort(sortedValues);
this.values = sortedValues;
return this;
}
/**
@ -112,8 +113,9 @@ public class HDRPercentileRanksAggregator extends AbstractHDRPercentilesAggregat
/**
* Set whether the XContent response should be keyed
*/
public void keyed(boolean keyed) {
public Factory keyed(boolean keyed) {
this.keyed = keyed;
return this;
}
/**
@ -126,8 +128,9 @@ public class HDRPercentileRanksAggregator extends AbstractHDRPercentilesAggregat
/**
* Expert: set the number of significant digits in the values.
*/
public void numberOfSignificantValueDigits(int numberOfSignificantValueDigits) {
public Factory numberOfSignificantValueDigits(int numberOfSignificantValueDigits) {
this.numberOfSignificantValueDigits = numberOfSignificantValueDigits;
return this;
}
/**
@ -153,7 +156,7 @@ public class HDRPercentileRanksAggregator extends AbstractHDRPercentilesAggregat
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
Factory factory = new Factory(name);
factory.values = in.readDoubleArray();

View File

@ -84,7 +84,7 @@ public class HDRPercentilesAggregator extends AbstractHDRPercentilesAggregator {
formatter, pipelineAggregators(), metaData());
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, Factory> {
private double[] percents = PercentilesParser.DEFAULT_PERCENTS;
private int numberOfSignificantValueDigits = 3;
@ -97,10 +97,11 @@ public class HDRPercentilesAggregator extends AbstractHDRPercentilesAggregator {
/**
* Set the percentiles to compute.
*/
public void percents(double[] percents) {
public Factory percents(double[] percents) {
double[] sortedPercents = Arrays.copyOf(percents, percents.length);
Arrays.sort(sortedPercents);
this.percents = sortedPercents;
return this;
}
/**
@ -113,8 +114,9 @@ public class HDRPercentilesAggregator extends AbstractHDRPercentilesAggregator {
/**
* Set whether the XContent response should be keyed
*/
public void keyed(boolean keyed) {
public Factory keyed(boolean keyed) {
this.keyed = keyed;
return this;
}
/**
@ -127,8 +129,9 @@ public class HDRPercentilesAggregator extends AbstractHDRPercentilesAggregator {
/**
* Expert: set the number of significant digits in the values.
*/
public void numberOfSignificantValueDigits(int numberOfSignificantValueDigits) {
public Factory numberOfSignificantValueDigits(int numberOfSignificantValueDigits) {
this.numberOfSignificantValueDigits = numberOfSignificantValueDigits;
return this;
}
/**
@ -154,7 +157,7 @@ public class HDRPercentilesAggregator extends AbstractHDRPercentilesAggregator {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
Factory factory = new Factory(name);
factory.percents = in.readDoubleArray();

View File

@ -78,7 +78,7 @@ public class TDigestPercentileRanksAggregator extends AbstractTDigestPercentiles
}
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, Factory> {
private double[] values;
private double compression = 100.0;
@ -91,10 +91,11 @@ public class TDigestPercentileRanksAggregator extends AbstractTDigestPercentiles
/**
* Set the values to compute percentiles from.
*/
public void values(double[] values) {
public Factory values(double[] values) {
double[] sortedValues = Arrays.copyOf(values, values.length);
Arrays.sort(sortedValues);
this.values = sortedValues;
return this;
}
/**
@ -107,8 +108,9 @@ public class TDigestPercentileRanksAggregator extends AbstractTDigestPercentiles
/**
* Set whether the XContent response should be keyed
*/
public void keyed(boolean keyed) {
public Factory keyed(boolean keyed) {
this.keyed = keyed;
return this;
}
/**
@ -122,8 +124,9 @@ public class TDigestPercentileRanksAggregator extends AbstractTDigestPercentiles
* Expert: set the compression. Higher values improve accuracy but also
* memory usage.
*/
public void compression(double compression) {
public Factory compression(double compression) {
this.compression = compression;
return this;
}
/**
@ -150,7 +153,7 @@ public class TDigestPercentileRanksAggregator extends AbstractTDigestPercentiles
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
Factory factory = new Factory(name);
factory.values = in.readDoubleArray();

View File

@ -78,7 +78,7 @@ public class TDigestPercentilesAggregator extends AbstractTDigestPercentilesAggr
return new InternalTDigestPercentiles(name, keys, new TDigestState(compression), keyed, formatter, pipelineAggregators(), metaData());
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, Factory> {
private double[] percents = PercentilesParser.DEFAULT_PERCENTS;
private double compression = 100.0;
@ -91,10 +91,11 @@ public class TDigestPercentilesAggregator extends AbstractTDigestPercentilesAggr
/**
* Set the percentiles to compute.
*/
public void percents(double[] percents) {
public Factory percents(double[] percents) {
double[] sortedPercents = Arrays.copyOf(percents, percents.length);
Arrays.sort(sortedPercents);
this.percents = sortedPercents;
return this;
}
/**
@ -107,8 +108,9 @@ public class TDigestPercentilesAggregator extends AbstractTDigestPercentilesAggr
/**
* Set whether the XContent response should be keyed
*/
public void keyed(boolean keyed) {
public Factory keyed(boolean keyed) {
this.keyed = keyed;
return this;
}
/**
@ -122,8 +124,9 @@ public class TDigestPercentilesAggregator extends AbstractTDigestPercentilesAggr
* Expert: set the compression. Higher values improve accuracy but also
* memory usage.
*/
public void compression(double compression) {
public Factory compression(double compression) {
this.compression = compression;
return this;
}
/**
@ -150,7 +153,7 @@ public class TDigestPercentilesAggregator extends AbstractTDigestPercentilesAggr
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
Factory factory = new Factory(name);
factory.percents = in.readDoubleArray();

View File

@ -110,7 +110,7 @@ public class ScriptedMetricAggregator extends MetricsAggregator {
return new InternalScriptedMetric(name, null, reduceScript, pipelineAggregators(), metaData());
}
public static class Factory extends AggregatorFactory {
public static class Factory extends AggregatorFactory<Factory> {
private Script initScript;
private Script mapScript;
@ -125,37 +125,78 @@ public class ScriptedMetricAggregator extends MetricsAggregator {
/**
* Set the <tt>init</tt> script.
*/
public void initScript(Script initScript) {
public Factory initScript(Script initScript) {
this.initScript = initScript;
return this;
}
/**
* Get the <tt>init</tt> script.
*/
public Script initScript() {
return initScript;
}
/**
* Set the <tt>map</tt> script.
*/
public void mapScript(Script mapScript) {
public Factory mapScript(Script mapScript) {
this.mapScript = mapScript;
return this;
}
/**
* Get the <tt>map</tt> script.
*/
public Script mapScript() {
return mapScript;
}
/**
* Set the <tt>combine</tt> script.
*/
public void combineScript(Script combineScript) {
public Factory combineScript(Script combineScript) {
this.combineScript = combineScript;
return this;
}
/**
* Get the <tt>combine</tt> script.
*/
public Script combineScript() {
return combineScript;
}
/**
* Set the <tt>reduce</tt> script.
*/
public void reduceScript(Script reduceScript) {
public Factory reduceScript(Script reduceScript) {
this.reduceScript = reduceScript;
return this;
}
/**
* Get the <tt>reduce</tt> script.
*/
public Script reduceScript() {
return reduceScript;
}
/**
* Set parameters that will be available in the <tt>init</tt>,
* <tt>map</tt> and <tt>combine</tt> phases.
*/
public void params(Map<String, Object> params) {
public Factory params(Map<String, Object> params) {
this.params = params;
return this;
}
/**
* Get parameters that will be available in the <tt>init</tt>,
* <tt>map</tt> and <tt>combine</tt> phases.
*/
public Map<String, Object> params() {
return params;
}
@Override

View File

@ -36,7 +36,6 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
@ -160,7 +159,7 @@ public class StatsAggregator extends NumericMetricsAggregator.MultiValue {
return new InternalStats(name, 0, 0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, formatter, pipelineAggregators(), metaData());
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, Factory> {
public Factory(String name) {
super(name, InternalStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
@ -180,7 +179,7 @@ public class StatsAggregator extends NumericMetricsAggregator.MultiValue {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) {
return new StatsAggregator.Factory(name);
}

View File

@ -24,8 +24,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -52,7 +50,7 @@ public class StatsParser extends NumericValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected StatsAggregator.Factory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
return new StatsAggregator.Factory(aggregationName);
}

View File

@ -37,7 +37,6 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
@ -197,7 +196,7 @@ public class ExtendedStatsAggregator extends NumericMetricsAggregator.MultiValue
Releasables.close(counts, maxes, mins, sumOfSqrs, sums);
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, Factory> {
private double sigma = 2.0;
@ -205,8 +204,9 @@ public class ExtendedStatsAggregator extends NumericMetricsAggregator.MultiValue
super(name, InternalExtendedStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
}
public void sigma(double sigma) {
public Factory sigma(double sigma) {
this.sigma = sigma;
return this;
}
public double sigma() {
@ -229,7 +229,7 @@ public class ExtendedStatsAggregator extends NumericMetricsAggregator.MultiValue
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
ExtendedStatsAggregator.Factory factory = new ExtendedStatsAggregator.Factory(name);
factory.sigma = in.readDouble();

View File

@ -24,8 +24,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -58,7 +56,7 @@ public class ExtendedStatsParser extends NumericValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected ExtendedStatsAggregator.Factory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
ExtendedStatsAggregator.Factory factory = new ExtendedStatsAggregator.Factory(aggregationName);
Double sigma = (Double) otherOptions.get(ExtendedStatsAggregator.SIGMA_FIELD);
@ -69,7 +67,7 @@ public class ExtendedStatsParser extends NumericValuesSourceParser {
}
@Override
public AggregatorFactory[] getFactoryPrototypes() {
public AggregatorFactory<?>[] getFactoryPrototypes() {
return new AggregatorFactory[] { new ExtendedStatsAggregator.Factory(null) };
}
}

View File

@ -110,7 +110,7 @@ public class SumAggregator extends NumericMetricsAggregator.SingleValue {
return new InternalSum(name, 0.0, formatter, pipelineAggregators(), metaData());
}
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric> {
public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, Factory> {
public Factory(String name) {
super(name, InternalSum.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
@ -130,7 +130,7 @@ public class SumAggregator extends NumericMetricsAggregator.SingleValue {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected ValuesSourceAggregatorFactory<Numeric, Factory> innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) {
return new SumAggregator.Factory(name);
}

View File

@ -24,8 +24,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -52,7 +50,7 @@ public class SumParser extends NumericValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<Numeric> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected SumAggregator.Factory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
return new SumAggregator.Factory(aggregationName);
}

View File

@ -209,7 +209,7 @@ public class TopHitsAggregator extends MetricsAggregator {
Releasables.close(topDocsCollectors);
}
public static class Factory extends AggregatorFactory {
public static class Factory extends AggregatorFactory<Factory> {
private static final SortParseElement sortParseElement = new SortParseElement();
private int from = 0;
@ -231,8 +231,9 @@ public class TopHitsAggregator extends MetricsAggregator {
/**
* From index to start the search from. Defaults to <tt>0</tt>.
*/
public void from(int from) {
public Factory from(int from) {
this.from = from;
return this;
}
/**
@ -245,8 +246,9 @@ public class TopHitsAggregator extends MetricsAggregator {
/**
* The number of search hits to return. Defaults to <tt>10</tt>.
*/
public void size(int size) {
public Factory size(int size) {
this.size = size;
return this;
}
/**
@ -264,8 +266,9 @@ public class TopHitsAggregator extends MetricsAggregator {
* @param order
* The sort ordering
*/
public void sort(String name, SortOrder order) {
public Factory sort(String name, SortOrder order) {
sort(SortBuilders.fieldSort(name).order(order));
return this;
}
/**
@ -274,14 +277,15 @@ public class TopHitsAggregator extends MetricsAggregator {
* @param name
* The name of the field to sort by
*/
public void sort(String name) {
public Factory sort(String name) {
sort(SortBuilders.fieldSort(name));
return this;
}
/**
* Adds a sort builder.
*/
public void sort(SortBuilder sort) {
public Factory sort(SortBuilder sort) {
try {
if (sorts == null) {
sorts = new ArrayList<>();
@ -297,18 +301,20 @@ public class TopHitsAggregator extends MetricsAggregator {
} catch (IOException e) {
throw new RuntimeException(e);
}
return this;
}
/**
* Adds a sort builder.
*/
public void sorts(List<BytesReference> sorts) {
public Factory sorts(List<BytesReference> sorts) {
if (this.sorts == null) {
this.sorts = new ArrayList<>();
}
for (BytesReference sort : sorts) {
this.sorts.add(sort);
}
return this;
}
/**
@ -321,8 +327,9 @@ public class TopHitsAggregator extends MetricsAggregator {
/**
* Adds highlight to perform as part of the search.
*/
public void highlighter(HighlightBuilder highlightBuilder) {
public Factory highlighter(HighlightBuilder highlightBuilder) {
this.highlightBuilder = highlightBuilder;
return this;
}
/**
@ -336,12 +343,13 @@ public class TopHitsAggregator extends MetricsAggregator {
* Indicates whether the response should contain the stored _source for
* every hit
*/
public void fetchSource(boolean fetch) {
public Factory fetchSource(boolean fetch) {
if (this.fetchSourceContext == null) {
this.fetchSourceContext = new FetchSourceContext(fetch);
} else {
this.fetchSourceContext.fetchSource(fetch);
}
return this;
}
/**
@ -356,9 +364,10 @@ public class TopHitsAggregator extends MetricsAggregator {
* An optional exclude (optionally wildcarded) pattern to
* filter the returned _source
*/
public void fetchSource(@Nullable String include, @Nullable String exclude) {
public Factory fetchSource(@Nullable String include, @Nullable String exclude) {
fetchSource(include == null ? Strings.EMPTY_ARRAY : new String[] { include },
exclude == null ? Strings.EMPTY_ARRAY : new String[] { exclude });
return this;
}
/**
@ -373,15 +382,17 @@ public class TopHitsAggregator extends MetricsAggregator {
* An optional list of exclude (optionally wildcarded)
* pattern to filter the returned _source
*/
public void fetchSource(@Nullable String[] includes, @Nullable String[] excludes) {
public Factory fetchSource(@Nullable String[] includes, @Nullable String[] excludes) {
fetchSourceContext = new FetchSourceContext(includes, excludes);
return this;
}
/**
* Indicate how the _source should be fetched.
*/
public void fetchSource(@Nullable FetchSourceContext fetchSourceContext) {
public Factory fetchSource(@Nullable FetchSourceContext fetchSourceContext) {
this.fetchSourceContext = fetchSourceContext;
return this;
}
/**
@ -397,27 +408,30 @@ public class TopHitsAggregator extends MetricsAggregator {
* the search request. If none are specified, the source of the document
* will be return.
*/
public void field(String name) {
public Factory field(String name) {
if (fieldNames == null) {
fieldNames = new ArrayList<>();
}
fieldNames.add(name);
return this;
}
/**
* Sets the fields to load and return as part of the search request. If
* none are specified, the source of the document will be returned.
*/
public void fields(List<String> fields) {
public Factory fields(List<String> fields) {
this.fieldNames = fields;
return this;
}
/**
* Sets no fields to be loaded, resulting in only id and type to be
* returned per field.
*/
public void noFields() {
public Factory noFields() {
this.fieldNames = Collections.emptyList();
return this;
}
/**
@ -431,22 +445,24 @@ public class TopHitsAggregator extends MetricsAggregator {
* Adds a field to load from the field data cache and return as part of
* the search request.
*/
public void fieldDataField(String name) {
public Factory fieldDataField(String name) {
if (fieldDataFields == null) {
fieldDataFields = new ArrayList<>();
}
fieldDataFields.add(name);
return this;
}
/**
* Adds fields to load from the field data cache and return as part of
* the search request.
*/
public void fieldDataFields(List<String> names) {
public Factory fieldDataFields(List<String> names) {
if (fieldDataFields == null) {
fieldDataFields = new ArrayList<>();
}
fieldDataFields.addAll(names);
return this;
}
/**
@ -464,8 +480,9 @@ public class TopHitsAggregator extends MetricsAggregator {
* @param script
* The script
*/
public void scriptField(String name, Script script) {
public Factory scriptField(String name, Script script) {
scriptField(name, script, false);
return this;
}
/**
@ -476,18 +493,20 @@ public class TopHitsAggregator extends MetricsAggregator {
* @param script
* The script
*/
public void scriptField(String name, Script script, boolean ignoreFailure) {
public Factory scriptField(String name, Script script, boolean ignoreFailure) {
if (scriptFields == null) {
scriptFields = new ArrayList<>();
}
scriptFields.add(new ScriptField(name, script, ignoreFailure));
return this;
}
public void scriptFields(List<ScriptField> scriptFields) {
public Factory scriptFields(List<ScriptField> scriptFields) {
if (this.scriptFields == null) {
this.scriptFields = new ArrayList<>();
}
this.scriptFields.addAll(scriptFields);
return this;
}
/**
@ -501,8 +520,9 @@ public class TopHitsAggregator extends MetricsAggregator {
* Should each {@link org.elasticsearch.search.SearchHit} be returned
* with an explanation of the hit (ranking).
*/
public void explain(boolean explain) {
public Factory explain(boolean explain) {
this.explain = explain;
return this;
}
/**
@ -517,8 +537,9 @@ public class TopHitsAggregator extends MetricsAggregator {
* Should each {@link org.elasticsearch.search.SearchHit} be returned
* with a version associated with it.
*/
public void version(boolean version) {
public Factory version(boolean version) {
this.version = version;
return this;
}
/**
@ -533,8 +554,9 @@ public class TopHitsAggregator extends MetricsAggregator {
* Applies when sorting, and controls if scores will be tracked as well.
* Defaults to <tt>false</tt>.
*/
public void trackScores(boolean trackScores) {
public Factory trackScores(boolean trackScores) {
this.trackScores = trackScores;
return this;
}
/**
@ -607,7 +629,7 @@ public class TopHitsAggregator extends MetricsAggregator {
}
@Override
public AggregatorFactory subFactories(AggregatorFactories subFactories) {
public Factory subFactories(AggregatorFactories subFactories) {
throw new AggregationInitializationException("Aggregator [" + name + "] of type [" + type + "] cannot accept sub-aggregations");
}

View File

@ -28,6 +28,7 @@ import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.metrics.sum.SumAggregator;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder.ScriptField;
import org.elasticsearch.search.fetch.FieldsParseElement;
@ -73,7 +74,7 @@ public class TopHitsParser implements Aggregator.Parser {
}
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException {
public TopHitsAggregator.Factory parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException {
TopHitsAggregator.Factory factory = new TopHitsAggregator.Factory(aggregationName);
XContentParser.Token token;
String currentFieldName = null;

View File

@ -112,7 +112,7 @@ public class ValueCountAggregator extends NumericMetricsAggregator.SingleValue {
Releasables.close(counts);
}
public static class Factory<VS extends ValuesSource> extends ValuesSourceAggregatorFactory.LeafOnly<VS> {
public static class Factory<VS extends ValuesSource> extends ValuesSourceAggregatorFactory.LeafOnly<VS, Factory<VS>> {
public Factory(String name, ValuesSourceType valuesSourceType, ValueType valueType) {
super(name, InternalValueCount.TYPE, valuesSourceType, valueType);
@ -133,7 +133,7 @@ public class ValueCountAggregator extends NumericMetricsAggregator.SingleValue {
}
@Override
protected ValuesSourceAggregatorFactory<VS> innerReadFrom(String name, ValuesSourceType valuesSourceType,
protected ValuesSourceAggregatorFactory<VS, Factory<VS>> innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) {
return new ValueCountAggregator.Factory<VS>(name, valuesSourceType, targetValueType);
}

View File

@ -52,13 +52,14 @@ public class ValueCountParser extends AnyValuesSourceParser {
}
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected ValuesSourceAggregatorFactory<ValuesSource, ValueCountAggregator.Factory<ValuesSource>> createFactory(String aggregationName,
ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
return new ValueCountAggregator.Factory<ValuesSource>(aggregationName, valuesSourceType, targetValueType);
}
@Override
public AggregatorFactory[] getFactoryPrototypes() {
public AggregatorFactory<?>[] getFactoryPrototypes() {
return new AggregatorFactory[] { new ValueCountAggregator.Factory<ValuesSource>(null, null, null) };
}
}

View File

@ -34,7 +34,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
public abstract class BucketMetricsFactory extends PipelineAggregatorFactory {
public abstract class BucketMetricsFactory<AF extends BucketMetricsFactory<AF>> extends PipelineAggregatorFactory {
private String format = null;
private GapPolicy gapPolicy = GapPolicy.SKIP;
@ -46,8 +46,9 @@ public abstract class BucketMetricsFactory extends PipelineAggregatorFactory {
/**
* Sets the format to use on the output of this aggregation.
*/
public void format(String format) {
public AF format(String format) {
this.format = format;
return (AF) this;
}
/**
@ -68,8 +69,9 @@ public abstract class BucketMetricsFactory extends PipelineAggregatorFactory {
/**
* Sets the gap policy to use for this aggregation.
*/
public void gapPolicy(GapPolicy gapPolicy) {
public AF gapPolicy(GapPolicy gapPolicy) {
this.gapPolicy = gapPolicy;
return (AF) this;
}
/**

View File

@ -89,7 +89,7 @@ public class AvgBucketPipelineAggregator extends BucketMetricsPipelineAggregator
return new InternalSimpleValue(name(), avgValue, formatter, pipelineAggregators, metadata);
}
public static class Factory extends BucketMetricsFactory {
public static class Factory extends BucketMetricsFactory<Factory> {
public Factory(String name, String[] bucketsPaths) {
super(name, TYPE.name(), bucketsPaths);

View File

@ -96,7 +96,7 @@ public class MaxBucketPipelineAggregator extends BucketMetricsPipelineAggregator
return new InternalBucketMetricValue(name(), keys, maxValue, formatter, Collections.emptyList(), metaData());
}
public static class Factory extends BucketMetricsFactory {
public static class Factory extends BucketMetricsFactory<Factory> {
public Factory(String name, String[] bucketsPaths) {
super(name, TYPE.name(), bucketsPaths);

View File

@ -97,7 +97,7 @@ public class MinBucketPipelineAggregator extends BucketMetricsPipelineAggregator
return new InternalBucketMetricValue(name(), keys, minValue, formatter, Collections.emptyList(), metaData());
};
public static class Factory extends BucketMetricsFactory {
public static class Factory extends BucketMetricsFactory<Factory> {
public Factory(String name, String[] bucketsPaths) {
super(name, TYPE.name(), bucketsPaths);

View File

@ -124,7 +124,7 @@ public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAg
out.writeDoubleArray(percents);
}
public static class Factory extends BucketMetricsFactory {
public static class Factory extends BucketMetricsFactory<Factory> {
private double[] percents = new double[] { 1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0 };
@ -142,8 +142,9 @@ public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAg
/**
* Set the percentages to calculate percentiles for in this aggregation
*/
public void percents(double[] percents) {
public Factory percents(double[] percents) {
this.percents = percents;
return this;
}
@Override

View File

@ -95,7 +95,7 @@ public class StatsBucketPipelineAggregator extends BucketMetricsPipelineAggregat
return new InternalStatsBucket(name(), count, sum, min, max, formatter, pipelineAggregators, metadata);
}
public static class Factory extends BucketMetricsFactory {
public static class Factory extends BucketMetricsFactory<Factory> {
public Factory(String name, String[] bucketsPaths) {
super(name, TYPE.name(), bucketsPaths);

View File

@ -101,7 +101,7 @@ public class ExtendedStatsBucketPipelineAggregator extends BucketMetricsPipeline
return new InternalExtendedStatsBucket(name(), count, sum, min, max, sumOfSqrs, sigma, formatter, pipelineAggregators, metadata);
}
public static class Factory extends BucketMetricsFactory {
public static class Factory extends BucketMetricsFactory<Factory> {
private double sigma = 2.0;
@ -113,8 +113,9 @@ public class ExtendedStatsBucketPipelineAggregator extends BucketMetricsPipeline
* Set the value of sigma to use when calculating the standard deviation
* bounds
*/
public void sigma(double sigma) {
public Factory sigma(double sigma) {
this.sigma = sigma;
return this;
}
/**

View File

@ -85,7 +85,7 @@ public class SumBucketPipelineAggregator extends BucketMetricsPipelineAggregator
return new InternalSimpleValue(name(), sum, formatter, pipelineAggregators, metadata);
}
public static class Factory extends BucketMetricsFactory {
public static class Factory extends BucketMetricsFactory<Factory> {
public Factory(String name, String[] bucketsPaths) {
super(name, TYPE.name(), bucketsPaths);

View File

@ -176,8 +176,9 @@ public class BucketScriptPipelineAggregator extends PipelineAggregator {
/**
* Sets the format to use on the output of this aggregation.
*/
public void format(String format) {
public Factory format(String format) {
this.format = format;
return this;
}
/**
@ -198,8 +199,9 @@ public class BucketScriptPipelineAggregator extends PipelineAggregator {
/**
* Sets the gap policy to use for this aggregation.
*/
public void gapPolicy(GapPolicy gapPolicy) {
public Factory gapPolicy(GapPolicy gapPolicy) {
this.gapPolicy = gapPolicy;
return this;
}
/**

View File

@ -122,8 +122,9 @@ public class CumulativeSumPipelineAggregator extends PipelineAggregator {
/**
* Sets the format to use on the output of this aggregation.
*/
public void format(String format) {
public Factory format(String format) {
this.format = format;
return this;
}
/**

View File

@ -167,16 +167,31 @@ public class DerivativePipelineAggregator extends PipelineAggregator {
super(name, TYPE.name(), bucketsPaths);
}
public void format(String format) {
public Factory format(String format) {
this.format = format;
return this;
}
public void gapPolicy(GapPolicy gapPolicy) {
public String format() {
return format;
}
public Factory gapPolicy(GapPolicy gapPolicy) {
this.gapPolicy = gapPolicy;
return this;
}
public void units(String units) {
public GapPolicy gapPolicy() {
return gapPolicy;
}
public Factory units(String units) {
this.units = units;
return this;
}
public String units() {
return units;
}
@Override

View File

@ -154,8 +154,9 @@ public class BucketSelectorPipelineAggregator extends PipelineAggregator {
/**
* Sets the gap policy to use for this aggregation.
*/
public void gapPolicy(GapPolicy gapPolicy) {
public Factory gapPolicy(GapPolicy gapPolicy) {
this.gapPolicy = gapPolicy;
return this;
}
/**

View File

@ -294,8 +294,9 @@ public class MovAvgPipelineAggregator extends PipelineAggregator {
/**
* Sets the format to use on the output of this aggregation.
*/
public void format(String format) {
public Factory format(String format) {
this.format = format;
return this;
}
/**
@ -308,8 +309,9 @@ public class MovAvgPipelineAggregator extends PipelineAggregator {
/**
* Sets the GapPolicy to use on the output of this aggregation.
*/
public void gapPolicy(GapPolicy gapPolicy) {
public Factory gapPolicy(GapPolicy gapPolicy) {
this.gapPolicy = gapPolicy;
return this;
}
/**
@ -335,8 +337,9 @@ public class MovAvgPipelineAggregator extends PipelineAggregator {
* @param window
* Size of window
*/
public void window(int window) {
public Factory window(int window) {
this.window = window;
return this;
}
/**
@ -355,8 +358,9 @@ public class MovAvgPipelineAggregator extends PipelineAggregator {
* @param model
* A MovAvgModel which has been prepopulated with settings
*/
public void model(MovAvgModel model) {
public Factory model(MovAvgModel model) {
this.model = model;
return this;
}
/**
@ -376,8 +380,9 @@ public class MovAvgPipelineAggregator extends PipelineAggregator {
* @param predict
* Number of predictions to make
*/
public void predict(int predict) {
public Factory predict(int predict) {
this.predict = predict;
return this;
}
/**
@ -397,8 +402,9 @@ public class MovAvgPipelineAggregator extends PipelineAggregator {
* @param minimize
* If the model should be fit to the underlying data
*/
public void minimize(boolean minimize) {
public Factory minimize(boolean minimize) {
this.minimize = minimize;
return this;
}
/**

View File

@ -158,8 +158,9 @@ public class SerialDiffPipelineAggregator extends PipelineAggregator {
/**
* Sets the lag to use when calculating the serial difference.
*/
public void lag(int lag) {
public Factory lag(int lag) {
this.lag = lag;
return this;
}
/**
@ -172,8 +173,9 @@ public class SerialDiffPipelineAggregator extends PipelineAggregator {
/**
* Sets the format to use on the output of this aggregation.
*/
public void format(String format) {
public Factory format(String format) {
this.format = format;
return this;
}
/**
@ -186,8 +188,9 @@ public class SerialDiffPipelineAggregator extends PipelineAggregator {
/**
* Sets the GapPolicy to use on the output of this aggregation.
*/
public void gapPolicy(GapPolicy gapPolicy) {
public Factory gapPolicy(GapPolicy gapPolicy) {
this.gapPolicy = gapPolicy;
return this;
}
/**

View File

@ -27,7 +27,6 @@ import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.Script.ScriptField;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.joda.time.DateTimeZone;
import java.io.IOException;
@ -37,7 +36,8 @@ import java.util.Map;
/**
*
*/
public abstract class AbstractValuesSourceParser<VS extends ValuesSource> implements Aggregator.Parser {
public abstract class AbstractValuesSourceParser<VS extends ValuesSource>
implements Aggregator.Parser {
static final ParseField TIME_ZONE = new ParseField("time_zone");
public abstract static class AnyValuesSourceParser extends AbstractValuesSourceParser<ValuesSource> {
@ -84,7 +84,8 @@ public abstract class AbstractValuesSourceParser<VS extends ValuesSource> implem
}
@Override
public final AggregatorFactory parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException {
public final ValuesSourceAggregatorFactory<VS, ?> parse(String aggregationName, XContentParser parser, QueryParseContext context)
throws IOException {
String field = null;
Script script = null;
@ -145,7 +146,7 @@ public abstract class AbstractValuesSourceParser<VS extends ValuesSource> implem
}
}
ValuesSourceAggregatorFactory<VS> factory = createFactory(aggregationName, this.valuesSourceType, this.targetValueType,
ValuesSourceAggregatorFactory<VS, ?> factory = createFactory(aggregationName, this.valuesSourceType, this.targetValueType,
otherOptions);
factory.field(field);
factory.script(script);
@ -174,7 +175,7 @@ public abstract class AbstractValuesSourceParser<VS extends ValuesSource> implem
* method
* @return the created factory
*/
protected abstract ValuesSourceAggregatorFactory<VS> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
protected abstract ValuesSourceAggregatorFactory<VS, ?> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions);
/**

View File

@ -53,9 +53,11 @@ import java.util.Objects;
/**
*
*/
public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> extends AggregatorFactory {
public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource, AF extends ValuesSourceAggregatorFactory<VS, AF>>
extends AggregatorFactory<AF> {
public static abstract class LeafOnly<VS extends ValuesSource> extends ValuesSourceAggregatorFactory<VS> {
public static abstract class LeafOnly<VS extends ValuesSource, AF extends ValuesSourceAggregatorFactory<VS, AF>>
extends ValuesSourceAggregatorFactory<VS, AF> {
protected LeafOnly(String name, Type type, ValuesSourceParser.Input<VS> input) {
super(name, type, input);
@ -66,7 +68,7 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> ext
}
@Override
public AggregatorFactory subFactories(AggregatorFactories subFactories) {
public AF subFactories(AggregatorFactories subFactories) {
throw new AggregationInitializationException("Aggregator [" + name + "] of type [" + type + "] cannot accept sub-aggregations");
}
}
@ -109,8 +111,9 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> ext
/**
* Sets the field to use for this aggregation.
*/
public void field(String field) {
public AF field(String field) {
this.field = field;
return (AF) this;
}
/**
@ -123,8 +126,9 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> ext
/**
* Sets the script to use for this aggregation.
*/
public void script(Script script) {
public AF script(Script script) {
this.script = script;
return (AF) this;
}
/**
@ -137,8 +141,9 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> ext
/**
* Sets the {@link ValueType} for the value produced by this aggregation
*/
public void valueType(ValueType valueType) {
public AF valueType(ValueType valueType) {
this.valueType = valueType;
return (AF) this;
}
/**
@ -151,8 +156,9 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> ext
/**
* Sets the format to use for the output of the aggregation.
*/
public void format(String format) {
public AF format(String format) {
this.format = format;
return (AF) this;
}
/**
@ -166,8 +172,9 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> ext
* Sets the value to use when the aggregation finds a missing value in a
* document
*/
public void missing(Object missing) {
public AF missing(Object missing) {
this.missing = missing;
return (AF) this;
}
/**
@ -181,8 +188,9 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> ext
/**
* Sets the time zone to use for this aggregation
*/
public void timeZone(DateTimeZone timeZone) {
public AF timeZone(DateTimeZone timeZone) {
this.timeZone = timeZone;
return (AF) this;
}
/**
@ -376,13 +384,13 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> ext
}
@Override
protected final ValuesSourceAggregatorFactory<VS> doReadFrom(String name, StreamInput in) throws IOException {
protected final ValuesSourceAggregatorFactory<VS, AF> doReadFrom(String name, StreamInput in) throws IOException {
ValuesSourceType valuesSourceType = ValuesSourceType.ANY.readFrom(in);
ValueType targetValueType = null;
if (in.readBoolean()) {
targetValueType = ValueType.STRING.readFrom(in);
}
ValuesSourceAggregatorFactory<VS> factory = innerReadFrom(name, valuesSourceType, targetValueType, in);
ValuesSourceAggregatorFactory<VS, AF> factory = innerReadFrom(name, valuesSourceType, targetValueType, in);
factory.field = in.readOptionalString();
if (in.readBoolean()) {
factory.script = Script.readScript(in);
@ -399,7 +407,7 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> ext
}
// NORELEASE make this abstract when agg refactor complete
protected ValuesSourceAggregatorFactory<VS> innerReadFrom(String name, ValuesSourceType valuesSourceType, ValueType targetValueType,
protected ValuesSourceAggregatorFactory<VS, AF> innerReadFrom(String name, ValuesSourceType valuesSourceType, ValueType targetValueType,
StreamInput in) throws IOException {
return null;
}
@ -447,7 +455,7 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource> ext
@Override
protected final boolean doEquals(Object obj) {
ValuesSourceAggregatorFactory<?> other = (ValuesSourceAggregatorFactory<?>) obj;
ValuesSourceAggregatorFactory<?, ?> other = (ValuesSourceAggregatorFactory<?, ?>) obj;
if (!Objects.equals(field, other.field))
return false;
if (!Objects.equals(format, other.format))

View File

@ -24,8 +24,8 @@ import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
public abstract class AbstractNumericMetricTestCase<AF extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric>> extends
BaseAggregationTestCase<AF> {
public abstract class AbstractNumericMetricTestCase<AF extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource.Numeric, AF>>
extends BaseAggregationTestCase<AF> {
@Override
protected final AF createTestAggregatorFactory() {

View File

@ -28,11 +28,11 @@ public class FilterTests extends BaseAggregationTestCase<FilterAggregator.Factor
@Override
protected Factory createTestAggregatorFactory() {
Factory factory = new Factory(randomAsciiOfLengthBetween(1, 20));
Factory factory = new Factory(randomAsciiOfLengthBetween(1, 20),
QueryBuilders.termQuery(randomAsciiOfLengthBetween(5, 20), randomAsciiOfLengthBetween(5, 20)));
// NORELEASE make RandomQueryBuilder work outside of the
// AbstractQueryTestCase
// builder.query(RandomQueryBuilder.createQuery(getRandom()));
factory.filter(QueryBuilders.termQuery(randomAsciiOfLengthBetween(5, 20), randomAsciiOfLengthBetween(5, 20)));
return factory;
}