Removes the simple metric builders in place of AggFactory implementations

This commit is contained in:
Colin Goodheart-Smithe 2016-01-11 15:04:56 +00:00
parent 360fe98ca0
commit 8c4f0ea705
21 changed files with 71 additions and 539 deletions

View File

@ -52,31 +52,31 @@ import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
import org.elasticsearch.search.aggregations.metrics.avg.Avg; import org.elasticsearch.search.aggregations.metrics.avg.Avg;
import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregator; import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregator;
import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality;
import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityBuilder; import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregatorFactory;
import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds; import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds;
import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsBuilder; import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregator;
import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid; import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid;
import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidBuilder; import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregator;
import org.elasticsearch.search.aggregations.metrics.max.Max; import org.elasticsearch.search.aggregations.metrics.max.Max;
import org.elasticsearch.search.aggregations.metrics.max.MaxBuilder; import org.elasticsearch.search.aggregations.metrics.max.MaxAggregator;
import org.elasticsearch.search.aggregations.metrics.min.Min; import org.elasticsearch.search.aggregations.metrics.min.Min;
import org.elasticsearch.search.aggregations.metrics.min.MinBuilder; import org.elasticsearch.search.aggregations.metrics.min.MinAggregator;
import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks;
import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksBuilder; import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksBuilder;
import org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles; import org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles;
import org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesBuilder; import org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesBuilder;
import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetric; import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetric;
import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricBuilder; import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregator;
import org.elasticsearch.search.aggregations.metrics.stats.Stats; import org.elasticsearch.search.aggregations.metrics.stats.Stats;
import org.elasticsearch.search.aggregations.metrics.stats.StatsBuilder; import org.elasticsearch.search.aggregations.metrics.stats.StatsAggregator;
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats;
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregator; import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregator;
import org.elasticsearch.search.aggregations.metrics.sum.Sum; import org.elasticsearch.search.aggregations.metrics.sum.Sum;
import org.elasticsearch.search.aggregations.metrics.sum.SumBuilder; import org.elasticsearch.search.aggregations.metrics.sum.SumAggregator;
import org.elasticsearch.search.aggregations.metrics.tophits.TopHits; import org.elasticsearch.search.aggregations.metrics.tophits.TopHits;
import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsBuilder; import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsBuilder;
import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount; import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount;
import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountBuilder; import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregator;
/** /**
* Utility class to create aggregations. * Utility class to create aggregations.
@ -89,8 +89,8 @@ public class AggregationBuilders {
/** /**
* Create a new {@link ValueCount} aggregation with the given name. * Create a new {@link ValueCount} aggregation with the given name.
*/ */
public static ValueCountBuilder count(String name) { public static ValueCountAggregator.Factory count(String name) {
return new ValueCountBuilder(name); return new ValueCountAggregator.Factory(name, null);
} }
/** /**
@ -103,29 +103,29 @@ public class AggregationBuilders {
/** /**
* Create a new {@link Max} aggregation with the given name. * Create a new {@link Max} aggregation with the given name.
*/ */
public static MaxBuilder max(String name) { public static MaxAggregator.Factory max(String name) {
return new MaxBuilder(name); return new MaxAggregator.Factory(name);
} }
/** /**
* Create a new {@link Min} aggregation with the given name. * Create a new {@link Min} aggregation with the given name.
*/ */
public static MinBuilder min(String name) { public static MinAggregator.Factory min(String name) {
return new MinBuilder(name); return new MinAggregator.Factory(name);
} }
/** /**
* Create a new {@link Sum} aggregation with the given name. * Create a new {@link Sum} aggregation with the given name.
*/ */
public static SumBuilder sum(String name) { public static SumAggregator.Factory sum(String name) {
return new SumBuilder(name); return new SumAggregator.Factory(name);
} }
/** /**
* Create a new {@link Stats} aggregation with the given name. * Create a new {@link Stats} aggregation with the given name.
*/ */
public static StatsBuilder stats(String name) { public static StatsAggregator.Factory stats(String name) {
return new StatsBuilder(name); return new StatsAggregator.Factory(name);
} }
/** /**
@ -271,8 +271,8 @@ public class AggregationBuilders {
/** /**
* Create a new {@link Cardinality} aggregation with the given name. * Create a new {@link Cardinality} aggregation with the given name.
*/ */
public static CardinalityBuilder cardinality(String name) { public static CardinalityAggregatorFactory cardinality(String name) {
return new CardinalityBuilder(name); return new CardinalityAggregatorFactory(name, null);
} }
/** /**
@ -285,21 +285,21 @@ public class AggregationBuilders {
/** /**
* Create a new {@link GeoBounds} aggregation with the given name. * Create a new {@link GeoBounds} aggregation with the given name.
*/ */
public static GeoBoundsBuilder geoBounds(String name) { public static GeoBoundsAggregator.Factory geoBounds(String name) {
return new GeoBoundsBuilder(name); return new GeoBoundsAggregator.Factory(name);
} }
/** /**
* Create a new {@link GeoCentroid} aggregation with the given name. * Create a new {@link GeoCentroid} aggregation with the given name.
*/ */
public static GeoCentroidBuilder geoCentroid(String name) { public static GeoCentroidAggregator.Factory geoCentroid(String name) {
return new GeoCentroidBuilder(name); return new GeoCentroidAggregator.Factory(name);
} }
/** /**
* Create a new {@link ScriptedMetric} aggregation with the given name. * Create a new {@link ScriptedMetric} aggregation with the given name.
*/ */
public static ScriptedMetricBuilder scriptedMetric(String name) { public static ScriptedMetricAggregator.Factory scriptedMetric(String name) {
return new ScriptedMetricBuilder(name); return new ScriptedMetricAggregator.Factory(name);
} }
} }

View File

@ -85,10 +85,10 @@ public class MissingAggregator extends SingleBucketAggregator {
return new InternalMissing(name, 0, buildEmptySubAggregations(), pipelineAggregators(), metaData()); return new InternalMissing(name, 0, buildEmptySubAggregations(), pipelineAggregators(), metaData());
} }
public static class Factory<VS extends ValuesSource> extends ValuesSourceAggregatorFactory<VS, Factory<VS>> { public static class Factory extends ValuesSourceAggregatorFactory<ValuesSource, Factory> {
public Factory(String name, ValuesSourceType valuesSourceType, ValueType valueType) { public Factory(String name, ValueType targetValueType) {
super(name, InternalMissing.TYPE, valuesSourceType, valueType); super(name, InternalMissing.TYPE, ValuesSourceType.ANY, targetValueType);
} }
@Override @Override
@ -98,15 +98,15 @@ public class MissingAggregator extends SingleBucketAggregator {
} }
@Override @Override
protected MissingAggregator doCreateInternal(VS valuesSource, AggregationContext aggregationContext, Aggregator parent, protected MissingAggregator doCreateInternal(ValuesSource valuesSource, AggregationContext aggregationContext, Aggregator parent,
boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
return new MissingAggregator(name, factories, valuesSource, aggregationContext, parent, pipelineAggregators, metaData); return new MissingAggregator(name, factories, valuesSource, aggregationContext, parent, pipelineAggregators, metaData);
} }
@Override @Override
protected Factory<VS> innerReadFrom(String name, ValuesSourceType valuesSourceType, protected Factory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) { ValueType targetValueType, StreamInput in) {
return new Factory<VS>(name, valuesSourceType, targetValueType); return new Factory(name, targetValueType);
} }
@Override @Override

View File

@ -24,7 +24,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.AnyValuesSourceParser; import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.AnyValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException; import java.io.IOException;
@ -48,13 +47,13 @@ public class MissingParser extends AnyValuesSourceParser {
} }
@Override @Override
protected MissingAggregator.Factory<ValuesSource> createFactory(String aggregationName, ValuesSourceType valuesSourceType, protected MissingAggregator.Factory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) { ValueType targetValueType, Map<ParseField, Object> otherOptions) {
return new MissingAggregator.Factory<ValuesSource>(aggregationName, valuesSourceType, targetValueType); return new MissingAggregator.Factory(aggregationName, targetValueType);
} }
@Override @Override
public AggregatorFactory[] getFactoryPrototypes() { public AggregatorFactory[] getFactoryPrototypes() {
return new AggregatorFactory[] { new MissingAggregator.Factory<ValuesSource>(null, null, null) }; return new AggregatorFactory[] { new MissingAggregator.Factory(null, null) };
} }
} }

View File

@ -37,22 +37,21 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
public final class CardinalityAggregatorFactory<VS extends ValuesSource> public final class CardinalityAggregatorFactory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource, CardinalityAggregatorFactory> {
extends ValuesSourceAggregatorFactory.LeafOnly<VS, CardinalityAggregatorFactory<VS>> {
public static final ParseField PRECISION_THRESHOLD_FIELD = new ParseField("precision_threshold"); public static final ParseField PRECISION_THRESHOLD_FIELD = new ParseField("precision_threshold");
private Long precisionThreshold = null; private Long precisionThreshold = null;
public CardinalityAggregatorFactory(String name, ValuesSourceType valuesSourceType, ValueType valueType) { public CardinalityAggregatorFactory(String name, ValueType targetValueType) {
super(name, InternalCardinality.TYPE, valuesSourceType, valueType); super(name, InternalCardinality.TYPE, ValuesSourceType.ANY, targetValueType);
} }
/** /**
* Set a precision threshold. Higher values improve accuracy but also * Set a precision threshold. Higher values improve accuracy but also
* increase memory usage. * increase memory usage.
*/ */
public CardinalityAggregatorFactory<VS> precisionThreshold(long precisionThreshold) { public CardinalityAggregatorFactory precisionThreshold(long precisionThreshold) {
this.precisionThreshold = precisionThreshold; this.precisionThreshold = precisionThreshold;
return this; return this;
} }
@ -85,16 +84,16 @@ public final class CardinalityAggregatorFactory<VS extends ValuesSource>
} }
@Override @Override
protected Aggregator doCreateInternal(VS valuesSource, AggregationContext context, Aggregator parent, protected Aggregator doCreateInternal(ValuesSource valuesSource, AggregationContext context, Aggregator parent,
boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
return new CardinalityAggregator(name, valuesSource, precision(parent), config.formatter(), context, parent, pipelineAggregators, return new CardinalityAggregator(name, valuesSource, precision(parent), config.formatter(), context, parent, pipelineAggregators,
metaData); metaData);
} }
@Override @Override
protected CardinalityAggregatorFactory<VS> innerReadFrom(String name, ValuesSourceType valuesSourceType, protected CardinalityAggregatorFactory innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException { ValueType targetValueType, StreamInput in) throws IOException {
CardinalityAggregatorFactory<VS> factory = new CardinalityAggregatorFactory<>(name, valuesSourceType, targetValueType); CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory(name, targetValueType);
if (in.readBoolean()) { if (in.readBoolean()) {
factory.precisionThreshold = in.readLong(); factory.precisionThreshold = in.readLong();
} }
@ -125,7 +124,7 @@ public final class CardinalityAggregatorFactory<VS extends ValuesSource>
@Override @Override
protected boolean innerEquals(Object obj) { protected boolean innerEquals(Object obj) {
CardinalityAggregatorFactory<ValuesSource> other = (CardinalityAggregatorFactory<ValuesSource>) obj; CardinalityAggregatorFactory other = (CardinalityAggregatorFactory) obj;
return Objects.equals(precisionThreshold, other.precisionThreshold); return Objects.equals(precisionThreshold, other.precisionThreshold);
} }

View File

@ -1,71 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.metrics.cardinality;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.aggregations.metrics.ValuesSourceMetricsAggregationBuilder;
import java.io.IOException;
/**
* Builder for the {@link Cardinality} aggregation.
*/
public class CardinalityBuilder extends ValuesSourceMetricsAggregationBuilder<CardinalityBuilder> {
private Long precisionThreshold;
private Boolean rehash;
/**
* Sole constructor.
*/
public CardinalityBuilder(String name) {
super(name, InternalCardinality.TYPE.name());
}
/**
* Set a precision threshold. Higher values improve accuracy but also
* increase memory usage.
*/
public CardinalityBuilder precisionThreshold(long precisionThreshold) {
this.precisionThreshold = precisionThreshold;
return this;
}
/**
* Expert: set to false in case values of this field can already be treated
* as 64-bits hash values.
*/
public CardinalityBuilder rehash(boolean rehash) {
this.rehash = rehash;
return this;
}
@Override
protected void internalXContent(XContentBuilder builder, Params params) throws IOException {
super.internalXContent(builder, params);
if (precisionThreshold != null) {
builder.field("precision_threshold", precisionThreshold);
}
if (rehash != null) {
builder.field("rehash", rehash);
}
}
}

View File

@ -26,7 +26,6 @@ import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.AnyValuesSourceParser; import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.AnyValuesSourceParser;
import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException; import java.io.IOException;
@ -47,10 +46,9 @@ public class CardinalityParser extends AnyValuesSourceParser {
} }
@Override @Override
protected CardinalityAggregatorFactory<ValuesSource> createFactory(String aggregationName, ValuesSourceType valuesSourceType, protected CardinalityAggregatorFactory createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) { ValueType targetValueType, Map<ParseField, Object> otherOptions) {
CardinalityAggregatorFactory<ValuesSource> factory = new CardinalityAggregatorFactory<>(aggregationName, valuesSourceType, CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory(aggregationName, targetValueType);
targetValueType);
Long precisionThreshold = (Long) otherOptions.get(CardinalityAggregatorFactory.PRECISION_THRESHOLD_FIELD); Long precisionThreshold = (Long) otherOptions.get(CardinalityAggregatorFactory.PRECISION_THRESHOLD_FIELD);
if (precisionThreshold != null) { if (precisionThreshold != null) {
factory.precisionThreshold(precisionThreshold); factory.precisionThreshold(precisionThreshold);
@ -75,6 +73,6 @@ public class CardinalityParser extends AnyValuesSourceParser {
@Override @Override
public AggregatorFactory[] getFactoryPrototypes() { public AggregatorFactory[] getFactoryPrototypes() {
return new AggregatorFactory[] { new CardinalityAggregatorFactory<ValuesSource>(null, null, null) }; return new AggregatorFactory[] { new CardinalityAggregatorFactory(null, null) };
} }
} }

View File

@ -1,57 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.metrics.geobounds;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.aggregations.ValuesSourceAggregationBuilder;
import java.io.IOException;
/**
* Builder for the {@link GeoBounds} aggregation.
*/
public class GeoBoundsBuilder extends ValuesSourceAggregationBuilder<GeoBoundsBuilder> {
private Boolean wrapLongitude;
/**
* Sole constructor.
*/
public GeoBoundsBuilder(String name) {
super(name, InternalGeoBounds.TYPE.name());
}
/**
* Set whether to wrap longitudes. Defaults to true.
*/
public GeoBoundsBuilder wrapLongitude(boolean wrapLongitude) {
this.wrapLongitude = wrapLongitude;
return this;
}
@Override
protected XContentBuilder doInternalXContent(XContentBuilder builder, Params params) throws IOException {
if (wrapLongitude != null) {
builder.field("wrap_longitude", wrapLongitude);
}
return builder;
}
}

View File

@ -1,33 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.metrics.geocentroid;
import org.elasticsearch.search.aggregations.metrics.ValuesSourceMetricsAggregationBuilder;
/**
* Builder class for {@link org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregator}
*/
public class GeoCentroidBuilder extends ValuesSourceMetricsAggregationBuilder<GeoCentroidBuilder> {
public GeoCentroidBuilder(String name) {
super(name, InternalGeoCentroid.TYPE.name());
}
}

View File

@ -1,35 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.metrics.max;
import org.elasticsearch.search.aggregations.metrics.ValuesSourceMetricsAggregationBuilder;
/**
* Builder for the {@link Max} aggregation.
*/
public class MaxBuilder extends ValuesSourceMetricsAggregationBuilder<MaxBuilder> {
/**
* Sole constructor.
*/
public MaxBuilder(String name) {
super(name, InternalMax.TYPE.name());
}
}

View File

@ -1,35 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.metrics.min;
import org.elasticsearch.search.aggregations.metrics.ValuesSourceMetricsAggregationBuilder;
/**
* Builder for the {@link Min} aggregation.
*/
public class MinBuilder extends ValuesSourceMetricsAggregationBuilder<MinBuilder> {
/**
* Sole constructor.
*/
public MinBuilder(String name) {
super(name, InternalMin.TYPE.name());
}
}

View File

@ -1,112 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.metrics.scripted;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.metrics.MetricsAggregationBuilder;
import java.io.IOException;
import java.util.Map;
/**
* Builder for the {@link ScriptedMetric} aggregation.
*/
public class ScriptedMetricBuilder extends MetricsAggregationBuilder<ScriptedMetricBuilder> {
private Script initScript = null;
private Script mapScript = null;
private Script combineScript = null;
private Script reduceScript = null;
private Map<String, Object> params = null;
/**
* Sole constructor.
*/
public ScriptedMetricBuilder(String name) {
super(name, InternalScriptedMetric.TYPE.name());
}
/**
* Set the <tt>init</tt> script.
*/
public ScriptedMetricBuilder initScript(Script initScript) {
this.initScript = initScript;
return this;
}
/**
* Set the <tt>map</tt> script.
*/
public ScriptedMetricBuilder mapScript(Script mapScript) {
this.mapScript = mapScript;
return this;
}
/**
* Set the <tt>combine</tt> script.
*/
public ScriptedMetricBuilder combineScript(Script combineScript) {
this.combineScript = combineScript;
return this;
}
/**
* Set the <tt>reduce</tt> script.
*/
public ScriptedMetricBuilder reduceScript(Script reduceScript) {
this.reduceScript = reduceScript;
return this;
}
/**
* Set parameters that will be available in the <tt>init</tt>, <tt>map</tt>
* and <tt>combine</tt> phases.
*/
public ScriptedMetricBuilder params(Map<String, Object> params) {
this.params = params;
return this;
}
@Override
protected void internalXContent(XContentBuilder builder, Params builderParams) throws IOException {
if (initScript != null) {
builder.field(ScriptedMetricParser.INIT_SCRIPT_FIELD.getPreferredName(), initScript);
}
if (mapScript != null) {
builder.field(ScriptedMetricParser.MAP_SCRIPT_FIELD.getPreferredName(), mapScript);
}
if (combineScript != null) {
builder.field(ScriptedMetricParser.COMBINE_SCRIPT_FIELD.getPreferredName(), combineScript);
}
if (reduceScript != null) {
builder.field(ScriptedMetricParser.REDUCE_SCRIPT_FIELD.getPreferredName(), reduceScript);
}
if (params != null) {
builder.field(ScriptedMetricParser.PARAMS_FIELD.getPreferredName());
builder.map(params);
}
}
}

View File

@ -1,35 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.metrics.stats;
import org.elasticsearch.search.aggregations.metrics.ValuesSourceMetricsAggregationBuilder;
/**
* Builder for the {@link Stats} aggregation.
*/
public class StatsBuilder extends ValuesSourceMetricsAggregationBuilder<StatsBuilder> {
/**
* Sole constructor.
*/
public StatsBuilder(String name) {
super(name, InternalStats.TYPE.name());
}
}

View File

@ -1,35 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.metrics.sum;
import org.elasticsearch.search.aggregations.metrics.ValuesSourceMetricsAggregationBuilder;
/**
* Builder for the {@link Sum} aggregation.
*/
public class SumBuilder extends ValuesSourceMetricsAggregationBuilder<SumBuilder> {
/**
* Sole constructor.
*/
public SumBuilder(String name) {
super(name, InternalSum.TYPE.name());
}
}

View File

@ -112,10 +112,10 @@ public class ValueCountAggregator extends NumericMetricsAggregator.SingleValue {
Releasables.close(counts); Releasables.close(counts);
} }
public static class Factory<VS extends ValuesSource> extends ValuesSourceAggregatorFactory.LeafOnly<VS, Factory<VS>> { public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly<ValuesSource, Factory> {
public Factory(String name, ValuesSourceType valuesSourceType, ValueType valueType) { public Factory(String name, ValueType targetValueType) {
super(name, InternalValueCount.TYPE, valuesSourceType, valueType); super(name, InternalValueCount.TYPE, ValuesSourceType.ANY, targetValueType);
} }
@Override @Override
@ -125,7 +125,7 @@ public class ValueCountAggregator extends NumericMetricsAggregator.SingleValue {
} }
@Override @Override
protected Aggregator doCreateInternal(VS valuesSource, AggregationContext aggregationContext, Aggregator parent, protected Aggregator doCreateInternal(ValuesSource valuesSource, AggregationContext aggregationContext, Aggregator parent,
boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
throws IOException { throws IOException {
return new ValueCountAggregator(name, valuesSource, config.formatter(), aggregationContext, parent, pipelineAggregators, return new ValueCountAggregator(name, valuesSource, config.formatter(), aggregationContext, parent, pipelineAggregators,
@ -133,9 +133,9 @@ public class ValueCountAggregator extends NumericMetricsAggregator.SingleValue {
} }
@Override @Override
protected ValuesSourceAggregatorFactory<VS, Factory<VS>> innerReadFrom(String name, ValuesSourceType valuesSourceType, protected ValuesSourceAggregatorFactory<ValuesSource, Factory> innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) { ValueType targetValueType, StreamInput in) {
return new ValueCountAggregator.Factory<VS>(name, valuesSourceType, targetValueType); return new ValueCountAggregator.Factory(name, targetValueType);
} }
@Override @Override

View File

@ -1,36 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.metrics.valuecount;
import org.elasticsearch.search.aggregations.metrics.ValuesSourceMetricsAggregationBuilder;
/**
* Builder for the {@link ValueCount} aggregation.
*/
public class ValueCountBuilder extends ValuesSourceMetricsAggregationBuilder<ValueCountBuilder> {
/**
* Sole constructor.
*/
public ValueCountBuilder(String name) {
super(name, InternalValueCount.TYPE.name());
}
}

View File

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

View File

@ -21,16 +21,13 @@ package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.BaseAggregationTestCase; import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregator; import org.elasticsearch.search.aggregations.bucket.missing.MissingAggregator;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
public class MissingTests extends BaseAggregationTestCase<ValueCountAggregator.Factory<? extends ValuesSource>> { public class MissingTests extends BaseAggregationTestCase<MissingAggregator.Factory> {
@Override @Override
protected final ValueCountAggregator.Factory<? extends ValuesSource> createTestAggregatorFactory() { protected final MissingAggregator.Factory createTestAggregatorFactory() {
ValueCountAggregator.Factory<ValuesSource> factory = new ValueCountAggregator.Factory<ValuesSource>("foo", ValuesSourceType.ANY, MissingAggregator.Factory factory = new MissingAggregator.Factory("foo", null);
null);
String field = randomNumericField(); String field = randomNumericField();
int randomFieldBranch = randomInt(3); int randomFieldBranch = randomInt(3);
switch (randomFieldBranch) { switch (randomFieldBranch) {

View File

@ -22,15 +22,12 @@ package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.BaseAggregationTestCase; import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregator; import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregator;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
public class ValueCountTests extends BaseAggregationTestCase<ValueCountAggregator.Factory<? extends ValuesSource>> { public class ValueCountTests extends BaseAggregationTestCase<ValueCountAggregator.Factory> {
@Override @Override
protected final ValueCountAggregator.Factory<? extends ValuesSource> createTestAggregatorFactory() { protected final ValueCountAggregator.Factory createTestAggregatorFactory() {
ValueCountAggregator.Factory<ValuesSource> factory = new ValueCountAggregator.Factory<ValuesSource>("foo", ValuesSourceType.ANY, ValueCountAggregator.Factory factory = new ValueCountAggregator.Factory("foo", null);
null);
String field = randomNumericField(); String field = randomNumericField();
int randomFieldBranch = randomInt(3); int randomFieldBranch = randomInt(3);
switch (randomFieldBranch) { switch (randomFieldBranch) {

View File

@ -21,15 +21,12 @@ package org.elasticsearch.search.aggregations.metrics.cardinality;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.BaseAggregationTestCase; import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
public class CardinalityTests extends BaseAggregationTestCase<CardinalityAggregatorFactory<? extends ValuesSource>> { public class CardinalityTests extends BaseAggregationTestCase<CardinalityAggregatorFactory> {
@Override @Override
protected final CardinalityAggregatorFactory<? extends ValuesSource> createTestAggregatorFactory() { protected final CardinalityAggregatorFactory createTestAggregatorFactory() {
CardinalityAggregatorFactory<ValuesSource> factory = new CardinalityAggregatorFactory<ValuesSource>("foo", ValuesSourceType.ANY, CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory("foo", null);
null);
String field = randomNumericField(); String field = randomNumericField();
int randomFieldBranch = randomInt(3); int randomFieldBranch = randomInt(3);
switch (randomFieldBranch) { switch (randomFieldBranch) {

View File

@ -26,10 +26,7 @@ import org.elasticsearch.common.collect.EvictingQueue;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram; import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram;
import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram.Bucket; import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram.Bucket;
import org.elasticsearch.search.aggregations.metrics.ValuesSourceMetricsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.avg.Avg; import org.elasticsearch.search.aggregations.metrics.avg.Avg;
import org.elasticsearch.search.aggregations.metrics.max.MaxAggregator;
import org.elasticsearch.search.aggregations.metrics.min.MinAggregator;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregationHelperTests; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregationHelperTests;
import org.elasticsearch.search.aggregations.pipeline.SimpleValue; import org.elasticsearch.search.aggregations.pipeline.SimpleValue;
@ -1365,9 +1362,9 @@ public class MovAvgIT extends ESIntegTestCase {
switch (rand) { switch (rand) {
case 0: case 0:
return new MinAggregator.Factory(name).field(field); return min(name).field(field);
case 2: case 2:
return new MaxAggregator.Factory(name).field(field); return max(name).field(field);
case 3: case 3:
return avg(name).field(field); return avg(name).field(field);
default: default:

View File

@ -25,8 +25,6 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.collect.EvictingQueue; import org.elasticsearch.common.collect.EvictingQueue;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram; import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram;
import org.elasticsearch.search.aggregations.metrics.max.MaxAggregator;
import org.elasticsearch.search.aggregations.metrics.min.MinAggregator;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregationHelperTests; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregationHelperTests;
import org.elasticsearch.search.aggregations.pipeline.SimpleValue; import org.elasticsearch.search.aggregations.pipeline.SimpleValue;
@ -88,9 +86,9 @@ public class SerialDiffIT extends ESIntegTestCase {
switch (rand) { switch (rand) {
case 0: case 0:
return new MinAggregator.Factory(name).field(field); return min(name).field(field);
case 2: case 2:
return new MaxAggregator.Factory(name).field(field); return max(name).field(field);
case 3: case 3:
return avg(name).field(field); return avg(name).field(field);
default: default: