diff --git a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/ArrayValuesSourceAggregatorFactory.java b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/ArrayValuesSourceAggregatorFactory.java index 147f2157b0a..ca674c6e846 100644 --- a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/ArrayValuesSourceAggregatorFactory.java +++ b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/ArrayValuesSourceAggregatorFactory.java @@ -50,9 +50,9 @@ public abstract class ArrayValuesSourceAggregatorFactory HashMap valuesSources = new HashMap<>(); for (Map.Entry config : configs.entrySet()) { - ValuesSource vs = config.getValue().toValuesSource(); - if (vs != null) { - valuesSources.put(config.getKey(), vs); + ValuesSourceConfig vsc = config.getValue(); + if (vsc.hasValues()) { + valuesSources.put(config.getKey(), vsc.getValuesSource()); } } if (valuesSources.isEmpty()) { diff --git a/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsAggregatorTests.java b/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsAggregatorTests.java index f7c1e06ab68..d2170a13dad 100644 --- a/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsAggregatorTests.java +++ b/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsAggregatorTests.java @@ -61,6 +61,27 @@ public class MatrixStatsAggregatorTests extends AggregatorTestCase { } } + public void testUnmapped() throws Exception { + MappedFieldType ft = + new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE); + ft.setName("field"); + + try (Directory directory = newDirectory(); + RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) { + if (randomBoolean()) { + indexWriter.addDocument(Collections.singleton(new StringField("another_field", "value", Field.Store.NO))); + } + try (IndexReader reader = indexWriter.getReader()) { + IndexSearcher searcher = new IndexSearcher(reader); + MatrixStatsAggregationBuilder aggBuilder = new MatrixStatsAggregationBuilder("my_agg") + .fields(Collections.singletonList("bogus")); + InternalMatrixStats stats = search(searcher, new MatchAllDocsQuery(), aggBuilder, ft); + assertNull(stats.getStats()); + assertFalse(MatrixAggregationInspectionHelper.hasValue(stats)); + } + } + } + public void testTwoFields() throws Exception { String fieldA = "a"; MappedFieldType ftA = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE); diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregatorFactory.java b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregatorFactory.java index f13c0d19453..d16a8aea46d 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregatorFactory.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregatorFactory.java @@ -68,11 +68,11 @@ public class ChildrenAggregatorFactory extends ValuesSourceAggregatorFactory { } @Override - protected Aggregator doCreateInternal(ValuesSource rawValuesSource, - SearchContext searchContext, Aggregator parent, + protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { + ValuesSource rawValuesSource = config.getValuesSource(); if (rawValuesSource instanceof WithOrdinals == false) { throw new AggregationExecutionException("ValuesSource type " + rawValuesSource.toString() + "is not supported for aggregation " + this.name()); diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregatorFactory.java b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregatorFactory.java index 4ca45b457c0..13fc2fd0098 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregatorFactory.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregatorFactory.java @@ -69,11 +69,11 @@ public class ParentAggregatorFactory extends ValuesSourceAggregatorFactory { } @Override - protected Aggregator doCreateInternal(ValuesSource rawValuesSource, - SearchContext searchContext, Aggregator children, + protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator children, boolean collectsFromSingleBucket, Map metadata) throws IOException { + ValuesSource rawValuesSource = config.getValuesSource(); if (rawValuesSource instanceof WithOrdinals == false) { throw new AggregationExecutionException("ValuesSource type " + rawValuesSource.toString() + "is not supported for aggregation " + this.name()); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java index 13b1ad18fea..837540daf21 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java @@ -249,7 +249,7 @@ public class DateHistogramValuesSourceBuilder @Override protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException { Rounding rounding = dateHistogramInterval.createRounding(timeZone(), offset); - ValuesSource orig = config.toValuesSource(); + ValuesSource orig = config.hasValues() ? config.getValuesSource() : null; if (orig == null) { orig = ValuesSource.Numeric.EMPTY; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java index c74d62e623e..533f112aed4 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java @@ -129,7 +129,7 @@ public class GeoTileGridValuesSourceBuilder extends CompositeValuesSourceBuilder @Override protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException { - ValuesSource orig = config.toValuesSource(); + ValuesSource orig = config.hasValues() ? config.getValuesSource() : null; if (orig == null) { orig = ValuesSource.GeoPoint.EMPTY; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java index 4ef15908ddd..d422ac4dbbe 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java @@ -111,7 +111,7 @@ public class HistogramValuesSourceBuilder extends CompositeValuesSourceBuilder metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry() .getAggregator(config, GeoHashGridAggregationBuilder.NAME); if (aggregatorSupplier instanceof GeoGridAggregatorSupplier == false) { throw new AggregationExecutionException("Registry miss-match - expected " + GeoGridAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((GeoGridAggregatorSupplier) aggregatorSupplier).build(name, factories, valuesSource, precision, geoBoundingBox, + return ((GeoGridAggregatorSupplier) aggregatorSupplier).build(name, factories, config.getValuesSource(), precision, geoBoundingBox, requiredSize, shardSize, searchContext, parent, collectsFromSingleBucket, metadata); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileGridAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileGridAggregatorFactory.java index 57dcf1c5ce5..af0d0e137ed 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileGridAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileGridAggregatorFactory.java @@ -72,18 +72,17 @@ public class GeoTileGridAggregatorFactory extends ValuesSourceAggregatorFactory } @Override - protected Aggregator doCreateInternal(final ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry() .getAggregator(config, GeoTileGridAggregationBuilder.NAME); if (aggregatorSupplier instanceof GeoGridAggregatorSupplier == false) { throw new AggregationExecutionException("Registry miss-match - expected " + GeoGridAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((GeoGridAggregatorSupplier) aggregatorSupplier).build(name, factories, valuesSource, precision, geoBoundingBox, + return ((GeoGridAggregatorSupplier) aggregatorSupplier).build(name, factories, config.getValuesSource(), precision, geoBoundingBox, requiredSize, shardSize, searchContext, parent, collectsFromSingleBucket, metadata); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java index 3725c24deeb..49340ed5aae 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java @@ -22,7 +22,6 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.CollectionUtil; -import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Rounding; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.LongHash; @@ -38,6 +37,7 @@ import org.elasticsearch.search.aggregations.bucket.DeferringBucketCollector; import org.elasticsearch.search.aggregations.bucket.MergingBucketsDeferringCollector; import org.elasticsearch.search.aggregations.bucket.histogram.AutoDateHistogramAggregationBuilder.RoundingInfo; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -48,7 +48,7 @@ import java.util.function.Function; /** * An aggregator for date values that attempts to return a specific number of * buckets, reconfiguring how it rounds dates to buckets on the fly as new - * data arrives. + * data arrives. */ class AutoDateHistogramAggregator extends DeferableBucketAggregator { @@ -63,14 +63,23 @@ class AutoDateHistogramAggregator extends DeferableBucketAggregator { private int targetBuckets; private MergingBucketsDeferringCollector deferringCollector; - AutoDateHistogramAggregator(String name, AggregatorFactories factories, int numBuckets, RoundingInfo[] roundingInfos, - Function roundingPreparer, @Nullable ValuesSource valuesSource, DocValueFormat formatter, - SearchContext aggregationContext, Aggregator parent, Map metadata) throws IOException { + AutoDateHistogramAggregator( + String name, + AggregatorFactories factories, + int numBuckets, + RoundingInfo[] roundingInfos, + Function roundingPreparer, + ValuesSourceConfig valuesSourceConfig, + SearchContext aggregationContext, + Aggregator parent, + Map metadata + ) throws IOException { super(name, factories, aggregationContext, parent, metadata); this.targetBuckets = numBuckets; - this.valuesSource = (ValuesSource.Numeric) valuesSource; - this.formatter = formatter; + // TODO: Remove null usage here, by using a different aggregator for create + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.Numeric) valuesSourceConfig.getValuesSource() : null; + this.formatter = valuesSourceConfig.format(); this.roundingInfos = roundingInfos; this.roundingPreparer = roundingPreparer; preparedRounding = roundingPreparer.apply(roundingInfos[roundingIdx].rounding); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorFactory.java index f81d7afcd51..98871bad9ad 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorFactory.java @@ -28,7 +28,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.AutoDateHistogramAggregationBuilder.RoundingInfo; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -64,11 +63,10 @@ public final class AutoDateHistogramAggregatorFactory extends ValuesSourceAggreg } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { if (collectsFromSingleBucket == false) { return asMultiBucketAggregator(this, searchContext, parent); } @@ -79,16 +77,16 @@ public final class AutoDateHistogramAggregatorFactory extends ValuesSourceAggreg aggregatorSupplier.getClass().toString() + "]"); } Function roundingPreparer = - valuesSource.roundingPreparer(searchContext.getQueryShardContext().getIndexReader()); + config.getValuesSource().roundingPreparer(searchContext.getQueryShardContext().getIndexReader()); return ((AutoDateHistogramAggregatorSupplier) aggregatorSupplier).build(name, factories, numBuckets, roundingInfos, - roundingPreparer, valuesSource, config.format(), searchContext, parent, metadata); + roundingPreparer, config, searchContext, parent, metadata); } @Override protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new AutoDateHistogramAggregator(name, factories, numBuckets, roundingInfos, Rounding::prepareForUnknown, null, - config.format(), searchContext, parent, metadata); + return new AutoDateHistogramAggregator(name, factories, numBuckets, roundingInfos, Rounding::prepareForUnknown, + config, searchContext, parent, metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorSupplier.java index e5c286f431c..8ecf7094696 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorSupplier.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorSupplier.java @@ -21,11 +21,10 @@ package org.elasticsearch.search.aggregations.bucket.histogram; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Rounding; -import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -41,8 +40,7 @@ public interface AutoDateHistogramAggregatorSupplier extends AggregatorSupplier AutoDateHistogramAggregationBuilder.RoundingInfo[] roundingInfos, @Nullable Function roundingPreparer, - @Nullable ValuesSource valuesSource, - DocValueFormat formatter, + ValuesSourceConfig valuesSourceConfig, SearchContext aggregationContext, Aggregator parent, Map metadata diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationSupplier.java index 743e50c1e60..36cb9ce1f65 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationSupplier.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationSupplier.java @@ -21,12 +21,11 @@ package org.elasticsearch.search.aggregations.bucket.histogram; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Rounding; -import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -42,8 +41,7 @@ public interface DateHistogramAggregationSupplier extends AggregatorSupplier { boolean keyed, long minDocCount, @Nullable ExtendedBounds extendedBounds, - @Nullable ValuesSource valuesSource, - DocValueFormat formatter, + ValuesSourceConfig valuesSourceConfig, SearchContext aggregationContext, Aggregator parent, boolean collectsFromSingleBucket, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java index b3437cd7d93..3e3f640bb90 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java @@ -35,6 +35,7 @@ import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.bucket.BucketsAggregator; import org.elasticsearch.search.aggregations.bucket.terms.LongKeyedBucketOrds; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -65,11 +66,21 @@ class DateHistogramAggregator extends BucketsAggregator { private final LongKeyedBucketOrds bucketOrds; - DateHistogramAggregator(String name, AggregatorFactories factories, Rounding rounding, Rounding.Prepared preparedRounding, - BucketOrder order, boolean keyed, - long minDocCount, @Nullable ExtendedBounds extendedBounds, @Nullable ValuesSource valuesSource, - DocValueFormat formatter, SearchContext aggregationContext, - Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { + DateHistogramAggregator( + String name, + AggregatorFactories factories, + Rounding rounding, + Rounding.Prepared preparedRounding, + BucketOrder order, + boolean keyed, + long minDocCount, + @Nullable ExtendedBounds extendedBounds, + ValuesSourceConfig valuesSourceConfig, + SearchContext aggregationContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata + ) throws IOException { super(name, factories, aggregationContext, parent, metadata); this.rounding = rounding; @@ -79,8 +90,9 @@ class DateHistogramAggregator extends BucketsAggregator { this.keyed = keyed; this.minDocCount = minDocCount; this.extendedBounds = extendedBounds; - this.valuesSource = (ValuesSource.Numeric) valuesSource; - this.formatter = formatter; + // TODO: Stop using null here + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.Numeric) valuesSourceConfig.getValuesSource() : null; + this.formatter = valuesSourceConfig.format(); bucketOrds = LongKeyedBucketOrds.build(context.bigArrays(), collectsFromSingleBucket); } @@ -129,7 +141,7 @@ class DateHistogramAggregator extends BucketsAggregator { @Override public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws IOException { - return buildAggregationsForVariableBuckets(owningBucketOrds, bucketOrds, + return buildAggregationsForVariableBuckets(owningBucketOrds, bucketOrds, (bucketValue, docCount, subAggregationResults) -> { return new InternalDateHistogram.Bucket(bucketValue, docCount, keyed, formatter, subAggregationResults); }, buckets -> { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorFactory.java index 010605fc62c..5295971f04d 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorFactory.java @@ -29,7 +29,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -76,18 +75,21 @@ public final class DateHistogramAggregatorFactory extends ValuesSourceAggregator } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal( + SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, DateHistogramAggregationBuilder.NAME); if (aggregatorSupplier instanceof DateHistogramAggregationSupplier == false) { throw new AggregationExecutionException("Registry miss-match - expected DateHistogramAggregationSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - Rounding.Prepared preparedRounding = valuesSource.roundingPreparer(queryShardContext.getIndexReader()).apply(shardRounding); + // TODO: Is there a reason not to get the prepared rounding in the supplier itself? + Rounding.Prepared preparedRounding = config.getValuesSource() + .roundingPreparer(queryShardContext.getIndexReader()) + .apply(shardRounding); return ((DateHistogramAggregationSupplier) aggregatorSupplier).build( name, factories, @@ -97,8 +99,7 @@ public final class DateHistogramAggregatorFactory extends ValuesSourceAggregator keyed, minDocCount, extendedBounds, - valuesSource, - config.format(), + config, searchContext, parent, collectsFromSingleBucket, @@ -111,6 +112,6 @@ public final class DateHistogramAggregatorFactory extends ValuesSourceAggregator Aggregator parent, Map metadata) throws IOException { return new DateHistogramAggregator(name, factories, rounding, null, order, keyed, minDocCount, extendedBounds, - null, config.format(), searchContext, parent, false, metadata); + config, searchContext, parent, false, metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateRangeHistogramAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateRangeHistogramAggregator.java index 860c679381b..238fc75ce18 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateRangeHistogramAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateRangeHistogramAggregator.java @@ -38,6 +38,7 @@ import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.bucket.BucketsAggregator; import org.elasticsearch.search.aggregations.bucket.terms.LongKeyedBucketOrds; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -69,11 +70,21 @@ class DateRangeHistogramAggregator extends BucketsAggregator { private final LongKeyedBucketOrds bucketOrds; - DateRangeHistogramAggregator(String name, AggregatorFactories factories, Rounding rounding, Rounding.Prepared preparedRounding, - BucketOrder order, boolean keyed, - long minDocCount, @Nullable ExtendedBounds extendedBounds, @Nullable ValuesSource valuesSource, - DocValueFormat formatter, SearchContext aggregationContext, - Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { + DateRangeHistogramAggregator( + String name, + AggregatorFactories factories, + Rounding rounding, + Rounding.Prepared preparedRounding, + BucketOrder order, + boolean keyed, + long minDocCount, + @Nullable ExtendedBounds extendedBounds, + ValuesSourceConfig valuesSourceConfig, + SearchContext aggregationContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata + ) throws IOException { super(name, factories, aggregationContext, parent, metadata); this.rounding = rounding; @@ -83,8 +94,9 @@ class DateRangeHistogramAggregator extends BucketsAggregator { this.keyed = keyed; this.minDocCount = minDocCount; this.extendedBounds = extendedBounds; - this.valuesSource = (ValuesSource.Range) valuesSource; - this.formatter = formatter; + // TODO: Stop using null here + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.Range) valuesSourceConfig.getValuesSource() : null; + this.formatter = valuesSourceConfig.format(); if (this.valuesSource.rangeType() != RangeType.DATE) { throw new IllegalArgumentException("Expected date range type but found range type [" + this.valuesSource.rangeType().name + "]"); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorFactory.java index adc48559833..720a4fc4017 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorFactory.java @@ -29,7 +29,6 @@ import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.search.aggregations.support.HistogramAggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -87,11 +86,10 @@ public final class HistogramAggregatorFactory extends ValuesSourceAggregatorFact } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, HistogramAggregationBuilder.NAME); if (aggregatorSupplier instanceof HistogramAggregatorSupplier == false) { @@ -100,7 +98,7 @@ public final class HistogramAggregatorFactory extends ValuesSourceAggregatorFact } HistogramAggregatorSupplier histogramAggregatorSupplier = (HistogramAggregatorSupplier) aggregatorSupplier; return histogramAggregatorSupplier.build(name, factories, interval, offset, order, keyed, minDocCount, minBound, maxBound, - valuesSource, config.format(), searchContext, parent, collectsFromSingleBucket, metadata); + config, searchContext, parent, collectsFromSingleBucket, metadata); } @Override @@ -108,6 +106,6 @@ public final class HistogramAggregatorFactory extends ValuesSourceAggregatorFact Aggregator parent, Map metadata) throws IOException { return new NumericHistogramAggregator(name, factories, interval, offset, order, keyed, minDocCount, minBound, maxBound, - null, config.format(), searchContext, parent, false, metadata); + config, searchContext, parent, false, metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/NumericHistogramAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/NumericHistogramAggregator.java index b4d0b233b8f..13091f3c4c9 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/NumericHistogramAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/NumericHistogramAggregator.java @@ -21,15 +21,14 @@ package org.elasticsearch.search.aggregations.bucket.histogram; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.ScoreMode; -import org.elasticsearch.common.Nullable; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; -import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -54,8 +53,7 @@ public class NumericHistogramAggregator extends AbstractHistogramAggregator { long minDocCount, double minBound, double maxBound, - @Nullable ValuesSource valuesSource, - DocValueFormat formatter, + ValuesSourceConfig valuesSourceConfig, SearchContext context, Aggregator parent, boolean collectsFromSingleBucket, @@ -71,13 +69,14 @@ public class NumericHistogramAggregator extends AbstractHistogramAggregator { minDocCount, minBound, maxBound, - formatter, + valuesSourceConfig.format(), context, parent, collectsFromSingleBucket, metadata ); - this.valuesSource = (ValuesSource.Numeric) valuesSource; + // TODO: Stop using null here + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.Numeric) valuesSourceConfig.getValuesSource() : null; } @Override diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/RangeHistogramAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/RangeHistogramAggregator.java index c51e1ce0d3d..612a78b4dd9 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/RangeHistogramAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/RangeHistogramAggregator.java @@ -21,17 +21,16 @@ package org.elasticsearch.search.aggregations.bucket.histogram; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.Nullable; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.mapper.RangeFieldMapper; import org.elasticsearch.index.mapper.RangeType; -import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -51,8 +50,7 @@ public class RangeHistogramAggregator extends AbstractHistogramAggregator { long minDocCount, double minBound, double maxBound, - @Nullable ValuesSource valuesSource, - DocValueFormat formatter, + ValuesSourceConfig valuesSourceConfig, SearchContext context, Aggregator parent, boolean collectsFromSingleBucket, @@ -68,13 +66,14 @@ public class RangeHistogramAggregator extends AbstractHistogramAggregator { minDocCount, minBound, maxBound, - formatter, + valuesSourceConfig.format(), context, parent, collectsFromSingleBucket, metadata ); - this.valuesSource = (ValuesSource.Range) valuesSource; + // TODO: Stop using nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.Range) valuesSourceConfig.getValuesSource() : null; if (this.valuesSource.rangeType().isNumeric() == false) { throw new IllegalArgumentException( "Expected numeric range type but found non-numeric range [" + this.valuesSource.rangeType().name + "]" diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregator.java index e4966263450..fe3fcf61bce 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregator.java @@ -28,6 +28,7 @@ import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.bucket.BucketsAggregator; import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -40,12 +41,13 @@ public class MissingAggregator extends BucketsAggregator implements SingleBucket public MissingAggregator( String name, AggregatorFactories factories, - ValuesSource valuesSource, + ValuesSourceConfig valuesSourceConfig, SearchContext aggregationContext, Aggregator parent, Map metadata) throws IOException { super(name, factories, aggregationContext, parent, metadata); - this.valuesSource = valuesSource; + // TODO: Stop using nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? valuesSourceConfig.getValuesSource() : null; } @Override diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorFactory.java index d25616a9fcd..35b592bc6a4 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -52,15 +51,14 @@ public class MissingAggregatorFactory extends ValuesSourceAggregatorFactory { protected MissingAggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new MissingAggregator(name, factories, null, searchContext, parent, metadata); + return new MissingAggregator(name, factories, config, searchContext, parent, metadata); } @Override - protected MissingAggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected MissingAggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { final AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry() .getAggregator(config, MissingAggregationBuilder.NAME); if (aggregatorSupplier instanceof MissingAggregatorSupplier == false) { @@ -68,8 +66,8 @@ public class MissingAggregatorFactory extends ValuesSourceAggregatorFactory { aggregatorSupplier.getClass().toString() + "]"); } - return (MissingAggregator) ((MissingAggregatorSupplier) aggregatorSupplier) - .build(name, factories, valuesSource, searchContext, parent, metadata); + return (MissingAggregator) ((MissingAggregatorSupplier) aggregatorSupplier).build(name, factories, config, searchContext, parent, + metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorSupplier.java index d06fadd22e2..f5d544a1f07 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorSupplier.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorSupplier.java @@ -19,11 +19,10 @@ package org.elasticsearch.search.aggregations.bucket.missing; -import org.elasticsearch.common.Nullable; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -34,7 +33,7 @@ public interface MissingAggregatorSupplier extends AggregatorSupplier { Aggregator build(String name, AggregatorFactories factories, - @Nullable ValuesSource valuesSource, + ValuesSourceConfig valuesSourceConfig, SearchContext aggregationContext, Aggregator parent, Map metadata) throws IOException; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeAggregatorFactory.java index 1c3126dd027..9fbcc7b8af9 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeAggregatorFactory.java @@ -28,7 +28,6 @@ import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Unmapped; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -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.ValuesSourceConfig; @@ -77,11 +76,10 @@ public class AbstractRangeAggregatorFactory extends ValuesSourc } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, aggregationTypeName); @@ -89,7 +87,17 @@ public class AbstractRangeAggregatorFactory extends ValuesSourc throw new AggregationExecutionException("Registry miss-match - expected RangeAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((RangeAggregatorSupplier)aggregatorSupplier).build(name, factories, (Numeric) valuesSource, config.format(), rangeFactory, - ranges, keyed, searchContext, parent, metadata); + return ((RangeAggregatorSupplier) aggregatorSupplier).build( + name, + factories, + (Numeric) config.getValuesSource(), + config.format(), + rangeFactory, + ranges, + keyed, + searchContext, + parent, + metadata + ); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/BinaryRangeAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/BinaryRangeAggregatorFactory.java index 899a5d52d33..5f789466a0a 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/BinaryRangeAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/BinaryRangeAggregatorFactory.java @@ -25,7 +25,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -62,8 +61,7 @@ public class BinaryRangeAggregatorFactory extends ValuesSourceAggregatorFactory } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, Aggregator parent, + protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, @@ -73,7 +71,7 @@ public class BinaryRangeAggregatorFactory extends ValuesSourceAggregatorFactory throw new AggregationExecutionException("Registry miss-match - expected IpRangeAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((IpRangeAggregatorSupplier) aggregatorSupplier).build(name, factories, valuesSource, config.format(), + return ((IpRangeAggregatorSupplier) aggregatorSupplier).build(name, factories, config.getValuesSource(), config.format(), ranges, keyed, searchContext, parent, metadata); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java index 9ce75af7fed..7fc52d2b852 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java @@ -85,11 +85,10 @@ public class GeoDistanceRangeAggregatorFactory extends ValuesSourceAggregatorFac } @Override - protected Aggregator doCreateInternal(final ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry() .getAggregator(config, GeoDistanceAggregationBuilder.NAME); if (aggregatorSupplier instanceof GeoDistanceAggregatorSupplier == false) { @@ -97,7 +96,7 @@ public class GeoDistanceRangeAggregatorFactory extends ValuesSourceAggregatorFac + GeoDistanceAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]"); } return ((GeoDistanceAggregatorSupplier) aggregatorSupplier).build(name, factories, distanceType, origin, - unit, config.toValuesSource(), config.format(), rangeFactory, ranges, keyed, searchContext, parent, metadata); + unit, config.getValuesSource(), config.format(), rangeFactory, ranges, keyed, searchContext, parent, metadata); } private static class DistanceSource extends ValuesSource.Numeric { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorFactory.java index 34dfa1df4c5..4bbd98d482b 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorFactory.java @@ -29,7 +29,6 @@ import org.elasticsearch.search.aggregations.NonCollectingAggregator; import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregator.ExecutionMode; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -47,15 +46,15 @@ public class DiversifiedAggregatorFactory extends ValuesSourceAggregatorFactory CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN), (DiversifiedAggregatorSupplier) (String name, int shardSize, AggregatorFactories factories, SearchContext context, - Aggregator parent, Map metadata, ValuesSource valuesSource, + Aggregator parent, Map metadata, ValuesSourceConfig valuesSourceConfig, int maxDocsPerValue, String executionHint) -> - new DiversifiedNumericSamplerAggregator(name, shardSize, factories, context, parent, metadata, valuesSource, + new DiversifiedNumericSamplerAggregator(name, shardSize, factories, context, parent, metadata, valuesSourceConfig, maxDocsPerValue) ); builder.register(DiversifiedAggregationBuilder.NAME, CoreValuesSourceType.BYTES, (DiversifiedAggregatorSupplier) (String name, int shardSize, AggregatorFactories factories, SearchContext context, - Aggregator parent, Map metadata, ValuesSource valuesSource, + Aggregator parent, Map metadata, ValuesSourceConfig valuesSourceConfig, int maxDocsPerValue, String executionHint) -> { ExecutionMode execution = null; if (executionHint != null) { @@ -66,10 +65,10 @@ public class DiversifiedAggregatorFactory extends ValuesSourceAggregatorFactory if (execution == null) { execution = ExecutionMode.GLOBAL_ORDINALS; } - if ((execution.needsGlobalOrdinals()) && (!(valuesSource instanceof ValuesSource.Bytes.WithOrdinals))) { + if ((execution.needsGlobalOrdinals()) && (valuesSourceConfig.hasGlobalOrdinals() == false)) { execution = ExecutionMode.MAP; } - return execution.create(name, factories, shardSize, maxDocsPerValue, valuesSource, context, parent, metadata); + return execution.create(name, factories, shardSize, maxDocsPerValue, valuesSourceConfig, context, parent, metadata); }); } @@ -88,20 +87,18 @@ public class DiversifiedAggregatorFactory extends ValuesSourceAggregatorFactory } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { - AggregatorSupplier supplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, - DiversifiedAggregationBuilder.NAME); + AggregatorSupplier supplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, DiversifiedAggregationBuilder.NAME); if (supplier instanceof DiversifiedAggregatorSupplier == false) { throw new AggregationExecutionException("Registry miss-match - expected " + DiversifiedAggregatorSupplier.class.toString() + ", found [" + supplier.getClass().toString() + "]"); } - return ((DiversifiedAggregatorSupplier) supplier).build(name, shardSize, factories, searchContext, parent, metadata, valuesSource, - maxDocsPerValue, executionHint); + return ((DiversifiedAggregatorSupplier) supplier).build(name, shardSize, factories, searchContext, parent, metadata, + config, maxDocsPerValue, executionHint); } @Override diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorSupplier.java index 5158517ba44..3eb2c0a9a3b 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorSupplier.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorSupplier.java @@ -22,7 +22,7 @@ package org.elasticsearch.search.aggregations.bucket.sampler; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -36,7 +36,7 @@ public interface DiversifiedAggregatorSupplier extends AggregatorSupplier { SearchContext context, Aggregator parent, Map metadata, - ValuesSource valuesSource, + ValuesSourceConfig valuesSourceConfig, int maxDocsPerValue, String executionHint) throws IOException; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedBytesHashSamplerAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedBytesHashSamplerAggregator.java index 260d6472a29..dc3b77de6f7 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedBytesHashSamplerAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedBytesHashSamplerAggregator.java @@ -32,6 +32,7 @@ import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.bucket.DeferringBucketCollector; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -47,12 +48,19 @@ public class DiversifiedBytesHashSamplerAggregator extends SamplerAggregator { private ValuesSource valuesSource; private int maxDocsPerValue; - DiversifiedBytesHashSamplerAggregator(String name, int shardSize, AggregatorFactories factories, - SearchContext context, Aggregator parent, Map metadata, - ValuesSource valuesSource, - int maxDocsPerValue) throws IOException { + DiversifiedBytesHashSamplerAggregator( + String name, + int shardSize, + AggregatorFactories factories, + SearchContext context, + Aggregator parent, + Map metadata, + ValuesSourceConfig valuesSourceConfig, + int maxDocsPerValue + ) throws IOException { super(name, shardSize, factories, context, parent, metadata); - this.valuesSource = valuesSource; + assert valuesSourceConfig.hasValues(); + this.valuesSource = valuesSourceConfig.getValuesSource(); this.maxDocsPerValue = maxDocsPerValue; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedMapSamplerAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedMapSamplerAggregator.java index 9f78b57797a..bef433dada6 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedMapSamplerAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedMapSamplerAggregator.java @@ -34,6 +34,7 @@ import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.bucket.DeferringBucketCollector; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -46,11 +47,19 @@ public class DiversifiedMapSamplerAggregator extends SamplerAggregator { private int maxDocsPerValue; private BytesRefHash bucketOrds; - DiversifiedMapSamplerAggregator(String name, int shardSize, AggregatorFactories factories, - SearchContext context, Aggregator parent, Map metadata, - ValuesSource valuesSource, int maxDocsPerValue) throws IOException { + DiversifiedMapSamplerAggregator( + String name, + int shardSize, + AggregatorFactories factories, + SearchContext context, + Aggregator parent, + Map metadata, + ValuesSourceConfig valuesSourceConfig, + int maxDocsPerValue + ) throws IOException { super(name, shardSize, factories, context, parent, metadata); - this.valuesSource = valuesSource; + assert valuesSourceConfig.hasValues(); + this.valuesSource = valuesSourceConfig.getValuesSource(); this.maxDocsPerValue = maxDocsPerValue; // Need to use super class shardSize since it is limited to maxDoc bucketOrds = new BytesRefHash(this.shardSize, context.bigArrays()); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java index 0a87ea4aa8b..0e640ac946d 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java @@ -31,6 +31,7 @@ import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.bucket.DeferringBucketCollector; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -42,11 +43,19 @@ public class DiversifiedNumericSamplerAggregator extends SamplerAggregator { private ValuesSource.Numeric valuesSource; private int maxDocsPerValue; - DiversifiedNumericSamplerAggregator(String name, int shardSize, AggregatorFactories factories, - SearchContext context, Aggregator parent, Map metadata, - ValuesSource valuesSource, int maxDocsPerValue) throws IOException { + DiversifiedNumericSamplerAggregator( + String name, + int shardSize, + AggregatorFactories factories, + SearchContext context, + Aggregator parent, + Map metadata, + ValuesSourceConfig valuesSourceConfig, + int maxDocsPerValue + ) throws IOException { super(name, shardSize, factories, context, parent, metadata); - this.valuesSource = (ValuesSource.Numeric) valuesSource; + assert valuesSourceConfig.hasValues(); + this.valuesSource = (ValuesSource.Numeric) valuesSourceConfig.getValuesSource(); this.maxDocsPerValue = maxDocsPerValue; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedOrdinalsSamplerAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedOrdinalsSamplerAggregator.java index 3e931ee1818..d791743cd39 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedOrdinalsSamplerAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedOrdinalsSamplerAggregator.java @@ -32,6 +32,7 @@ import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.bucket.DeferringBucketCollector; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -43,11 +44,19 @@ public class DiversifiedOrdinalsSamplerAggregator extends SamplerAggregator { private ValuesSource.Bytes.WithOrdinals.FieldData valuesSource; private int maxDocsPerValue; - DiversifiedOrdinalsSamplerAggregator(String name, int shardSize, AggregatorFactories factories, - SearchContext context, Aggregator parent, Map metadata, - ValuesSource.Bytes.WithOrdinals.FieldData valuesSource, int maxDocsPerValue) throws IOException { + DiversifiedOrdinalsSamplerAggregator( + String name, + int shardSize, + AggregatorFactories factories, + SearchContext context, + Aggregator parent, + Map metadata, + ValuesSourceConfig valuesSourceConfig, + int maxDocsPerValue + ) throws IOException { super(name, shardSize, factories, context, parent, metadata); - this.valuesSource = valuesSource; + assert valuesSourceConfig.hasValues(); + this.valuesSource = (ValuesSource.Bytes.WithOrdinals.FieldData) valuesSourceConfig.getValuesSource(); this.maxDocsPerValue = maxDocsPerValue; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregator.java index 6ace7b093fc..53566f9d828 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregator.java @@ -33,7 +33,7 @@ import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.bucket.DeferableBucketAggregator; import org.elasticsearch.search.aggregations.bucket.DeferringBucketCollector; import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator; -import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -63,12 +63,19 @@ public class SamplerAggregator extends DeferableBucketAggregator implements Sing MAP(new ParseField("map")) { @Override - Aggregator create(String name, AggregatorFactories factories, int shardSize, int maxDocsPerValue, ValuesSource valuesSource, - SearchContext context, Aggregator parent, Map metadata) throws IOException { + Aggregator create( + String name, + AggregatorFactories factories, + int shardSize, + int maxDocsPerValue, + ValuesSourceConfig valuesSourceConfig, + SearchContext context, + Aggregator parent, + Map metadata + ) throws IOException { return new DiversifiedMapSamplerAggregator(name, shardSize, factories, context, parent, metadata, - valuesSource, - maxDocsPerValue); + valuesSourceConfig, maxDocsPerValue); } @Override @@ -80,12 +87,19 @@ public class SamplerAggregator extends DeferableBucketAggregator implements Sing BYTES_HASH(new ParseField("bytes_hash")) { @Override - Aggregator create(String name, AggregatorFactories factories, int shardSize, int maxDocsPerValue, ValuesSource valuesSource, - SearchContext context, Aggregator parent, Map metadata) throws IOException { + Aggregator create( + String name, + AggregatorFactories factories, + int shardSize, + int maxDocsPerValue, + ValuesSourceConfig valuesSourceConfig, + SearchContext context, + Aggregator parent, + Map metadata + ) throws IOException { return new DiversifiedBytesHashSamplerAggregator(name, shardSize, factories, context, parent, metadata, - valuesSource, - maxDocsPerValue); + valuesSourceConfig, maxDocsPerValue); } @Override @@ -97,10 +111,18 @@ public class SamplerAggregator extends DeferableBucketAggregator implements Sing GLOBAL_ORDINALS(new ParseField("global_ordinals")) { @Override - Aggregator create(String name, AggregatorFactories factories, int shardSize, int maxDocsPerValue, ValuesSource valuesSource, - SearchContext context, Aggregator parent, Map metadata) throws IOException { + Aggregator create( + String name, + AggregatorFactories factories, + int shardSize, + int maxDocsPerValue, + ValuesSourceConfig valuesSourceConfig, + SearchContext context, + Aggregator parent, + Map metadata + ) throws IOException { return new DiversifiedOrdinalsSamplerAggregator(name, shardSize, factories, context, parent, metadata, - (ValuesSource.Bytes.WithOrdinals.FieldData) valuesSource, maxDocsPerValue); + valuesSourceConfig, maxDocsPerValue); } @Override @@ -125,8 +147,16 @@ public class SamplerAggregator extends DeferableBucketAggregator implements Sing this.parseField = parseField; } - abstract Aggregator create(String name, AggregatorFactories factories, int shardSize, int maxDocsPerValue, - ValuesSource valuesSource, SearchContext context, Aggregator parent, Map metadata) throws IOException; + abstract Aggregator create( + String name, + AggregatorFactories factories, + int shardSize, + int maxDocsPerValue, + ValuesSourceConfig valuesSourceConfig, + SearchContext context, + Aggregator parent, + Map metadata + ) throws IOException; abstract boolean needsGlobalOrdinals(); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorFactory.java index 373f4f547ea..747a481eeff 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorFactory.java @@ -151,11 +151,10 @@ public class RareTermsAggregatorFactory extends ValuesSourceAggregatorFactory { } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { if (collectsFromSingleBucket == false) { return asMultiBucketAggregator(this, searchContext, parent); } @@ -167,7 +166,7 @@ public class RareTermsAggregatorFactory extends ValuesSourceAggregatorFactory { aggregatorSupplier.getClass().toString() + "]"); } - return ((RareTermsAggregatorSupplier) aggregatorSupplier).build(name, factories, valuesSource, config.format(), + return ((RareTermsAggregatorSupplier) aggregatorSupplier).build(name, factories, config.getValuesSource(), config.format(), maxDocCount, precision, includeExclude, searchContext, parent, metadata); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/SignificantTermsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/SignificantTermsAggregatorFactory.java index 6e89707b26b..43fe3a0d005 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/SignificantTermsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/SignificantTermsAggregatorFactory.java @@ -187,14 +187,14 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac Map metadata) throws IOException { super(name, config, queryShardContext, parent, subFactoriesBuilder, metadata); - if (config.unmapped() == false) { + if (config.hasValues()) { if (config.fieldContext().fieldType().isSearchable() == false) { throw new IllegalArgumentException("SignificantText aggregation requires fields to be searchable, but [" + config.fieldContext().fieldType().name() + "] is not"); } } - if (config.unmapped() == false) { + if (config.hasValues()) { if (config.fieldContext().fieldType().isSearchable() == false) { throw new IllegalArgumentException("SignificantText aggregation requires fields to be searchable, but [" + config.fieldContext().fieldType().name() + "] is not"); @@ -293,11 +293,10 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, SignificantTermsAggregationBuilder.NAME); if (aggregatorSupplier instanceof SignificantTermsAggregatorSupplier == false) { @@ -325,7 +324,7 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac } // TODO we should refactor so that we don't need to use this Factory as a singleton (e.g. stop passing `this` to the aggregators) - return sigTermsAggregatorSupplier.build(name, factories, valuesSource, config.format(), + return sigTermsAggregatorSupplier.build(name, factories, config.getValuesSource(), config.format(), bucketCountThresholds, includeExclude, executionHint, searchContext, parent, significanceHeuristic, this, collectsFromSingleBucket, metadata); } @@ -398,7 +397,7 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac **/ remapGlobalOrd = false; } - + return new GlobalOrdinalsStringTermsAggregator( name, factories, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorFactory.java index e7d9e5b5a8e..9c59d03f8ff 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorFactory.java @@ -146,7 +146,7 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory { subAggCollectMode = pickSubAggColectMode(factories, bucketCountThresholds.getShardSize(), -1); } - ValuesSource.Numeric numericValuesSource = (ValuesSource.Numeric) valuesSource; + ValuesSource.Numeric numericValuesSource = (ValuesSource.Numeric) valuesSource; IncludeExclude.LongFilter longFilter = null; Function> resultStrategy; if (numericValuesSource.isFloatingPoint()) { @@ -223,8 +223,7 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory { } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, + protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { @@ -246,7 +245,7 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory { } bucketCountThresholds.ensureValidity(); - return termsAggregatorSupplier.build(name, factories, valuesSource, order, config.format(), + return termsAggregatorSupplier.build(name, factories, config.getValuesSource(), order, config.format(), bucketCountThresholds, includeExclude, executionHint, searchContext, parent, collectMode, showTermDocCountError, collectsFromSingleBucket, metadata); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregator.java index a13b075cc4c..e0a49994832 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregator.java @@ -46,10 +46,11 @@ class AvgAggregator extends NumericMetricsAggregator.SingleValue { DoubleArray compensations; DocValueFormat format; - AvgAggregator(String name, ValuesSourceConfig valuesSourceConfig, ValuesSource valuesSource, SearchContext context, + AvgAggregator(String name, ValuesSourceConfig valuesSourceConfig, SearchContext context, Aggregator parent, Map metadata) throws IOException { super(name, context, parent, metadata); - this.valuesSource = (ValuesSource.Numeric) valuesSource; + // TODO Stop expecting nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.Numeric) valuesSourceConfig.getValuesSource() : null; this.format = valuesSourceConfig.format(); if (valuesSource != null) { final BigArrays bigArrays = context.bigArrays(); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorFactory.java index b016df14179..cdcb6990b69 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -54,15 +53,14 @@ class AvgAggregatorFactory extends ValuesSourceAggregatorFactory { protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new AvgAggregator(name, config, null, searchContext, parent, metadata); + return new AvgAggregator(name, config, searchContext, parent, metadata); } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, AvgAggregationBuilder.NAME); @@ -70,6 +68,6 @@ class AvgAggregatorFactory extends ValuesSourceAggregatorFactory { throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata); + return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregator.java index b09fe139d6f..cd1cbb92a7f 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregator.java @@ -41,6 +41,7 @@ import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -62,13 +63,14 @@ public class CardinalityAggregator extends NumericMetricsAggregator.SingleValue public CardinalityAggregator( String name, - ValuesSource valuesSource, + ValuesSourceConfig valuesSourceConfig, int precision, SearchContext context, Aggregator parent, Map metadata) throws IOException { super(name, context, parent, metadata); - this.valuesSource = valuesSource; + // TODO: Stop using nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? valuesSourceConfig.getValuesSource() : null; this.precision = precision; this.counts = valuesSource == null ? null : new HyperLogLogPlusPlus(precision, context.bigArrays(), 1); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorFactory.java index 044b7aa69c7..b073392847f 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -58,15 +57,14 @@ class CardinalityAggregatorFactory extends ValuesSourceAggregatorFactory { protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new CardinalityAggregator(name, null, precision(), searchContext, parent, metadata); + return new CardinalityAggregator(name, config, precision(), searchContext, parent, metadata); } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, CardinalityAggregationBuilder.NAME); if (aggregatorSupplier instanceof CardinalityAggregatorSupplier == false) { @@ -74,7 +72,7 @@ class CardinalityAggregatorFactory extends ValuesSourceAggregatorFactory { aggregatorSupplier.getClass().toString() + "]"); } CardinalityAggregatorSupplier cardinalityAggregatorSupplier = (CardinalityAggregatorSupplier) aggregatorSupplier; - return cardinalityAggregatorSupplier.build(name, valuesSource, precision(), searchContext, parent, metadata); + return cardinalityAggregatorSupplier.build(name, config, precision(), searchContext, parent, metadata); } private int precision() { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorSupplier.java index e169a68614d..e0e94c4f5fc 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorSupplier.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorSupplier.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -29,7 +29,7 @@ import java.util.Map; public interface CardinalityAggregatorSupplier extends AggregatorSupplier { Aggregator build(String name, - ValuesSource valuesSource, + ValuesSourceConfig valuesSourceConfig, int precision, SearchContext context, Aggregator parent, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregator.java index 7e8258986a3..5519d8811be 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregator.java @@ -32,6 +32,7 @@ import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -53,11 +54,18 @@ class ExtendedStatsAggregator extends NumericMetricsAggregator.MultiValue { DoubleArray sumOfSqrs; DoubleArray compensationOfSqrs; - ExtendedStatsAggregator(String name, ValuesSource.Numeric valuesSource, DocValueFormat formatter, - SearchContext context, Aggregator parent, double sigma, Map metadata) throws IOException { + ExtendedStatsAggregator( + String name, + ValuesSourceConfig valuesSourceConfig, + SearchContext context, + Aggregator parent, + double sigma, + Map metadata + ) throws IOException { super(name, context, parent, metadata); - this.valuesSource = valuesSource; - this.format = formatter; + // TODO: stop depending on nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.Numeric) valuesSourceConfig.getValuesSource() : null; + this.format = valuesSourceConfig.format(); this.sigma = sigma; if (valuesSource != null) { final BigArrays bigArrays = context.bigArrays(); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorFactory.java index b74cf21a7ce..87bccb4e596 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorFactory.java @@ -26,8 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -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.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -62,12 +60,11 @@ class ExtendedStatsAggregatorFactory extends ValuesSourceAggregatorFactory { protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new ExtendedStatsAggregator(name, null, config.format(), searchContext, parent, sigma, metadata); + return new ExtendedStatsAggregator(name, config, searchContext, parent, sigma, metadata); } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, + protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { @@ -78,7 +75,6 @@ class ExtendedStatsAggregatorFactory extends ValuesSourceAggregatorFactory { throw new AggregationExecutionException("Registry miss-match - expected ExtendedStatsAggregatorProvider, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return new ExtendedStatsAggregator(name, (Numeric) valuesSource, config.format(), searchContext, - parent, sigma, metadata); + return new ExtendedStatsAggregator(name, config, searchContext, parent, sigma, metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorProvider.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorProvider.java index 2d232b07ec2..43aaf5b2bb9 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorProvider.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorProvider.java @@ -18,10 +18,9 @@ */ package org.elasticsearch.search.aggregations.metrics; -import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -30,8 +29,7 @@ import java.util.Map; public interface ExtendedStatsAggregatorProvider extends AggregatorSupplier { Aggregator build(String name, - ValuesSource.Numeric valuesSource, - DocValueFormat formatter, + ValuesSourceConfig valuesSourceConfig, SearchContext context, Aggregator parent, double sigma, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregator.java index 7ec2ad6fd9e..9b40c579e17 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregator.java @@ -31,6 +31,7 @@ import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -49,10 +50,17 @@ final class GeoBoundsAggregator extends MetricsAggregator { DoubleArray negLefts; DoubleArray negRights; - GeoBoundsAggregator(String name, SearchContext aggregationContext, Aggregator parent, - ValuesSource valuesSource, boolean wrapLongitude, Map metadata) throws IOException { + GeoBoundsAggregator( + String name, + SearchContext aggregationContext, + Aggregator parent, + ValuesSourceConfig valuesSourceConfig, + boolean wrapLongitude, + Map metadata + ) throws IOException { super(name, aggregationContext, parent, metadata); - this.valuesSource = (ValuesSource.GeoPoint) valuesSource; + // TODO: stop expecting nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.GeoPoint) valuesSourceConfig.getValuesSource() : null; this.wrapLongitude = wrapLongitude; if (valuesSource != null) { final BigArrays bigArrays = context.bigArrays(); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorFactory.java index b4148ef4770..5ba93d84dc2 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -54,15 +53,14 @@ class GeoBoundsAggregatorFactory extends ValuesSourceAggregatorFactory { protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new GeoBoundsAggregator(name, searchContext, parent, null, wrapLongitude, metadata); + return new GeoBoundsAggregator(name, searchContext, parent, config, wrapLongitude, metadata); } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry() .getAggregator(config, GeoBoundsAggregationBuilder.NAME); @@ -71,7 +69,7 @@ class GeoBoundsAggregatorFactory extends ValuesSourceAggregatorFactory { + GeoBoundsAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((GeoBoundsAggregatorSupplier) aggregatorSupplier).build(name, searchContext, parent, valuesSource, wrapLongitude, metadata); + return ((GeoBoundsAggregatorSupplier) aggregatorSupplier).build(name, searchContext, parent, config, wrapLongitude, metadata); } static void registerAggregators(ValuesSourceRegistry.Builder builder) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorSupplier.java index 55e0d38fa25..1c807dbe882 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorSupplier.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorSupplier.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -30,7 +30,11 @@ import java.util.Map; @FunctionalInterface public interface GeoBoundsAggregatorSupplier extends AggregatorSupplier { - MetricsAggregator build(String name, SearchContext aggregationContext, Aggregator parent, - ValuesSource valuesSource, boolean wrapLongitude, - Map metadata) throws IOException; + MetricsAggregator build( + String name, + SearchContext aggregationContext, + Aggregator parent, + ValuesSourceConfig valuesSourceConfig, + boolean wrapLongitude, + Map metadata) throws IOException; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregator.java index 87f9fed3425..025606b612d 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregator.java @@ -31,6 +31,7 @@ import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -44,10 +45,16 @@ final class GeoCentroidAggregator extends MetricsAggregator { private DoubleArray lonSum, lonCompensations, latSum, latCompensations; private LongArray counts; - GeoCentroidAggregator(String name, SearchContext context, Aggregator parent, - ValuesSource valuesSource, Map metadata) throws IOException { + GeoCentroidAggregator( + String name, + ValuesSourceConfig valuesSourceConfig, + SearchContext context, + Aggregator parent, + Map metadata + ) throws IOException { super(name, context, parent, metadata); - this.valuesSource = (ValuesSource.GeoPoint) valuesSource; + // TODO: Stop expecting nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.GeoPoint) valuesSourceConfig.getValuesSource() : null; if (valuesSource != null) { final BigArrays bigArrays = context.bigArrays(); lonSum = bigArrays.newDoubleArray(1, true); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorFactory.java index 27a1be909aa..4df88e5baa5 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -50,27 +49,26 @@ class GeoCentroidAggregatorFactory extends ValuesSourceAggregatorFactory { protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new GeoCentroidAggregator(name, searchContext, parent, null, metadata); + return new GeoCentroidAggregator(name, config, searchContext, parent, metadata); } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, GeoCentroidAggregationBuilder.NAME); - if (aggregatorSupplier instanceof GeoCentroidAggregatorSupplier == false) { + if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) { throw new AggregationExecutionException("Registry miss-match - expected " - + GeoCentroidAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]"); + + MetricAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((GeoCentroidAggregatorSupplier) aggregatorSupplier).build(name, searchContext, parent, valuesSource, metadata); + return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata); } static void registerAggregators(ValuesSourceRegistry.Builder builder) { builder.register(GeoCentroidAggregationBuilder.NAME, CoreValuesSourceType.GEOPOINT, - (GeoCentroidAggregatorSupplier) GeoCentroidAggregator::new); + (MetricAggregatorSupplier) GeoCentroidAggregator::new); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorSupplier.java deleted file mode 100644 index 0a8976fbd00..00000000000 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorSupplier.java +++ /dev/null @@ -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; - -import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.support.AggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.internal.SearchContext; - -import java.io.IOException; -import java.util.Map; - -@FunctionalInterface -public interface GeoCentroidAggregatorSupplier extends AggregatorSupplier { - - MetricsAggregator build(String name, SearchContext context, Aggregator parent, - ValuesSource valuesSource, - Map metadata) throws IOException; -} diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregator.java index 7b2547fc187..20e354d0157 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregator.java @@ -58,11 +58,11 @@ class MaxAggregator extends NumericMetricsAggregator.SingleValue { MaxAggregator(String name, ValuesSourceConfig config, - ValuesSource valuesSource, SearchContext context, Aggregator parent, Map metadata) throws IOException { super(name, context, parent, metadata); - this.valuesSource = (ValuesSource.Numeric) valuesSource; + // TODO stop expecting nulls here + this.valuesSource = config.hasValues() ? (ValuesSource.Numeric) config.getValuesSource() : null; if (valuesSource != null) { maxes = context.bigArrays().newDoubleArray(1, false); maxes.fill(0, maxes.size(), Double.NEGATIVE_INFINITY); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorFactory.java index 64a6cca392f..3f77dd244ac 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -53,15 +52,14 @@ class MaxAggregatorFactory extends ValuesSourceAggregatorFactory { protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new MaxAggregator(name, config, null, searchContext, parent, metadata); + return new MaxAggregator(name, config, searchContext, parent, metadata); } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, MaxAggregationBuilder.NAME); @@ -69,6 +67,6 @@ class MaxAggregatorFactory extends ValuesSourceAggregatorFactory { throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata); + return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorFactory.java index 0822ece7fc2..2d61ac6c213 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -73,11 +72,10 @@ public class MedianAbsoluteDeviationAggregatorFactory extends ValuesSourceAggreg } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, MedianAbsoluteDeviationAggregationBuilder.NAME); @@ -85,7 +83,7 @@ public class MedianAbsoluteDeviationAggregatorFactory extends ValuesSourceAggreg throw new AggregationExecutionException("Registry miss-match - expected MedianAbsoluteDeviationAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((MedianAbsoluteDeviationAggregatorSupplier) aggregatorSupplier).build(name, valuesSource, config.format(), + return ((MedianAbsoluteDeviationAggregatorSupplier) aggregatorSupplier).build(name, config.getValuesSource(), config.format(), searchContext, parent, metadata, compression); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MetricAggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MetricAggregatorSupplier.java index 533419f5478..cb5ae434720 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MetricAggregatorSupplier.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MetricAggregatorSupplier.java @@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; @@ -30,7 +29,6 @@ import java.util.Map; public interface MetricAggregatorSupplier extends AggregatorSupplier { Aggregator build(String name, ValuesSourceConfig valuesSourceConfig, - ValuesSource valuesSource, SearchContext context, Aggregator parent, Map metadata) throws IOException; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregator.java index fa8362fd4f9..8c5dd731c11 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregator.java @@ -61,12 +61,12 @@ class MinAggregator extends NumericMetricsAggregator.SingleValue { MinAggregator(String name, ValuesSourceConfig config, - ValuesSource valuesSource, SearchContext context, Aggregator parent, Map metadata) throws IOException { super(name, context, parent, metadata); - this.valuesSource = (ValuesSource.Numeric) valuesSource; + // TODO: Stop using nulls here + this.valuesSource = config.hasValues() ? (ValuesSource.Numeric) config.getValuesSource() : null; if (valuesSource != null) { mins = context.bigArrays().newDoubleArray(1, false); mins.fill(0, mins.size(), Double.POSITIVE_INFINITY); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregatorFactory.java index b9158dbefae..613b2338c76 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -53,15 +52,14 @@ class MinAggregatorFactory extends ValuesSourceAggregatorFactory { protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new MinAggregator(name, config, null, searchContext, parent, metadata); + return new MinAggregator(name, config, searchContext, parent, metadata); } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, MinAggregationBuilder.NAME); @@ -69,6 +67,6 @@ class MinAggregatorFactory extends ValuesSourceAggregatorFactory { throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata); + return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentileRanksAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentileRanksAggregatorFactory.java index 97e0c45c227..e5a6bcc1b39 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentileRanksAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentileRanksAggregatorFactory.java @@ -84,8 +84,7 @@ class PercentileRanksAggregatorFactory extends ValuesSourceAggregatorFactory { } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, + protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { @@ -97,7 +96,16 @@ class PercentileRanksAggregatorFactory extends ValuesSourceAggregatorFactory { aggregatorSupplier.getClass().toString() + "]"); } PercentilesAggregatorSupplier percentilesAggregatorSupplier = (PercentilesAggregatorSupplier) aggregatorSupplier; - return percentilesAggregatorSupplier.build(name, valuesSource, searchContext, parent, percents, percentilesConfig, keyed, - config.format(), metadata); + return percentilesAggregatorSupplier.build( + name, + config.getValuesSource(), + searchContext, + parent, + percents, + percentilesConfig, + keyed, + config.format(), + metadata + ); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java index ef4dbf5f7ec..584b512f1eb 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java @@ -83,8 +83,7 @@ class PercentilesAggregatorFactory extends ValuesSourceAggregatorFactory { } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, + protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { @@ -97,7 +96,16 @@ class PercentilesAggregatorFactory extends ValuesSourceAggregatorFactory { aggregatorSupplier.getClass().toString() + "]"); } PercentilesAggregatorSupplier percentilesAggregatorSupplier = (PercentilesAggregatorSupplier) aggregatorSupplier; - return percentilesAggregatorSupplier.build(name, valuesSource, searchContext, parent, percents, percentilesConfig, keyed, - config.format(), metadata); + return percentilesAggregatorSupplier.build( + name, + config.getValuesSource(), + searchContext, + parent, + percents, + percentilesConfig, + keyed, + config.format(), + metadata + ); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregator.java index 10579737510..06cab8ae5ef 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregator.java @@ -48,10 +48,16 @@ class StatsAggregator extends NumericMetricsAggregator.MultiValue { DoubleArray mins; DoubleArray maxes; - StatsAggregator(String name, ValuesSourceConfig valuesSourceConfig, ValuesSource valuesSource, - SearchContext context, Aggregator parent, Map metadata) throws IOException { + StatsAggregator( + String name, + ValuesSourceConfig valuesSourceConfig, + SearchContext context, + Aggregator parent, + Map metadata + ) throws IOException { super(name, context, parent, metadata); - this.valuesSource = (ValuesSource.Numeric) valuesSource; + // TODO: stop using nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.Numeric) valuesSourceConfig.getValuesSource() : null; if (valuesSource != null) { final BigArrays bigArrays = context.bigArrays(); counts = bigArrays.newLongArray(1, true); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorFactory.java index d0484d5ad05..15eedaea9e0 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -56,15 +55,14 @@ class StatsAggregatorFactory extends ValuesSourceAggregatorFactory { protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new StatsAggregator(name, config, null, searchContext, parent, metadata); + return new StatsAggregator(name, config, searchContext, parent, metadata); } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, StatsAggregationBuilder.NAME); @@ -72,6 +70,6 @@ class StatsAggregatorFactory extends ValuesSourceAggregatorFactory { throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata); + return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregator.java index 41294f3eff6..aebff3fbeff 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregator.java @@ -44,10 +44,16 @@ public class SumAggregator extends NumericMetricsAggregator.SingleValue { private DoubleArray sums; private DoubleArray compensations; - SumAggregator(String name, ValuesSourceConfig valuesSourceConfig, ValuesSource valuesSource, SearchContext context, - Aggregator parent, Map metadata) throws IOException { + SumAggregator( + String name, + ValuesSourceConfig valuesSourceConfig, + SearchContext context, + Aggregator parent, + Map metadata + ) throws IOException { super(name, context, parent, metadata); - this.valuesSource = (ValuesSource.Numeric) valuesSource; + // TODO: stop expecting nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? (ValuesSource.Numeric) valuesSourceConfig.getValuesSource() : null; this.format = valuesSourceConfig.format(); if (valuesSource != null) { sums = context.bigArrays().newDoubleArray(1, true); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorFactory.java index de182467939..1b184f5f9eb 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -57,15 +56,14 @@ class SumAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, Map metadata) throws IOException { - return new SumAggregator(name, config, null, searchContext, parent, metadata); + return new SumAggregator(name, config, searchContext, parent, metadata); } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, SumAggregationBuilder.NAME); @@ -73,6 +71,6 @@ class SumAggregatorFactory extends ValuesSourceAggregatorFactory { throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata); + return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregator.java index bc5c28938e5..3887565dc35 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregator.java @@ -30,6 +30,7 @@ import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -50,12 +51,13 @@ public class ValueCountAggregator extends NumericMetricsAggregator.SingleValue { public ValueCountAggregator( String name, - ValuesSource valuesSource, + ValuesSourceConfig valuesSourceConfig, SearchContext aggregationContext, Aggregator parent, Map metadata) throws IOException { super(name, aggregationContext, parent, metadata); - this.valuesSource = valuesSource; + // TODO: stop expecting nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? valuesSourceConfig.getValuesSource() : null; if (valuesSource != null) { counts = context.bigArrays().newLongArray(1, true); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorFactory.java index 367d299dc1a..9df68f9ba82 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorFactory.java @@ -26,7 +26,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -39,7 +38,7 @@ class ValueCountAggregatorFactory extends ValuesSourceAggregatorFactory { public static void registerAggregators(ValuesSourceRegistry.Builder builder) { builder.register(ValueCountAggregationBuilder.NAME, CoreValuesSourceType.ALL_CORE, - (ValueCountAggregatorSupplier) ValueCountAggregator::new); + (MetricAggregatorSupplier) ValueCountAggregator::new); } ValueCountAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext, @@ -52,22 +51,21 @@ class ValueCountAggregatorFactory extends ValuesSourceAggregatorFactory { protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException { - return new ValueCountAggregator(name, null, searchContext, parent, metadata); + return new ValueCountAggregator(name, config, searchContext, parent, metadata); } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { + protected Aggregator doCreateInternal(SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, ValueCountAggregationBuilder.NAME); - if (aggregatorSupplier instanceof ValueCountAggregatorSupplier == false) { - throw new AggregationExecutionException("Registry miss-match - expected ValueCountAggregatorSupplier, found [" + + if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) { + throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((ValueCountAggregatorSupplier) aggregatorSupplier) - .build(name, valuesSource, searchContext, parent, metadata); + return ((MetricAggregatorSupplier) aggregatorSupplier) + .build(name, config, searchContext, parent, metadata); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorSupplier.java deleted file mode 100644 index f882afaf1d0..00000000000 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorSupplier.java +++ /dev/null @@ -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; - -import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.support.AggregatorSupplier; -import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.internal.SearchContext; - -import java.io.IOException; -import java.util.Map; - -public interface ValueCountAggregatorSupplier extends AggregatorSupplier { - Aggregator build(String name, - ValuesSource valuesSource, - SearchContext aggregationContext, - Aggregator parent, - Map metadata) throws IOException; -} diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/AggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/AggregatorSupplier.java index 97ca793faed..0d8d7e3f3c7 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/AggregatorSupplier.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/AggregatorSupplier.java @@ -18,5 +18,21 @@ */ package org.elasticsearch.search.aggregations.support; +/** + * {@link AggregatorSupplier} serves as a marker for what the {@link ValuesSourceRegistry} holds to construct aggregator instances. + * The aggregators for each aggregation should all share a signature, and that signature should be used to create an AggregatorSupplier for + * that aggregation. Alternatively, if an existing supplier has a matching signature, please re-use that. + * + * In many cases, this can be a simple wrapper over the aggregator constructor. If that is sufficient, please just use a reference to the + * constructor. Implementing a supplier (typically as a lambda) should only be necessary when factors besides the {@link ValuesSourceType} + * are necessary for selecting the correct aggregator implementation. This happens in terms for example where we make decisions based on + * the availability of global ordinals. + * + * The suppliers are responsible for any casting of {@link ValuesSource} that needs to happen. They must accept a base {@link ValuesSource} + * instance. The suppliers may perform additional logic to configure the aggregator as needed, such as in + * {@link org.elasticsearch.search.aggregations.bucket.terms.TermsAggregatorFactory} deciding the execution mode. + * + * There is ongoing work to normalize aggregator constructor signatures, and thus reduce the number of AggregatorSupplier interfaces. + */ public interface AggregatorSupplier { } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/HistogramAggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/HistogramAggregatorSupplier.java index c349c50230d..4de0b9eb535 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/HistogramAggregatorSupplier.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/HistogramAggregatorSupplier.java @@ -18,11 +18,11 @@ */ package org.elasticsearch.search.aggregations.support; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.BucketOrder; +import org.elasticsearch.search.aggregations.support.AggregatorSupplier; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -39,8 +39,7 @@ public interface HistogramAggregatorSupplier extends AggregatorSupplier { long minDocCount, double minBound, double maxBound, - @Nullable ValuesSource valuesSource, - DocValueFormat formatter, + ValuesSourceConfig valuesSourceConfig, SearchContext context, Aggregator parent, boolean collectsFromSingleBucket, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSource.java index fe1d5be9932..376525deef6 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSource.java @@ -39,7 +39,7 @@ public abstract class MultiValuesSource { QueryShardContext context) { values = new HashMap<>(valuesSourceConfigs.size()); for (Map.Entry entry : valuesSourceConfigs.entrySet()) { - final ValuesSource valuesSource = entry.getValue().toValuesSource(); + final ValuesSource valuesSource = entry.getValue().getValuesSource(); if (valuesSource instanceof ValuesSource.Numeric == false) { throw new AggregationExecutionException("ValuesSource type " + valuesSource.toString() + "is not supported for multi-valued aggregation"); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSource.java index 1ca53144d81..1416b965469 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSource.java @@ -78,6 +78,13 @@ public abstract class ValuesSource { */ public abstract Function roundingPreparer(IndexReader reader) throws IOException; + /** + * Check if this values source supports using global ordinals + */ + public boolean hasGlobalOrdinals() { + return false; + } + public static class Range extends ValuesSource { private final RangeType rangeType; protected final IndexFieldData indexFieldData; @@ -166,6 +173,11 @@ public abstract class ValuesSource { return true; } + @Override + public boolean hasGlobalOrdinals() { + return true; + } + /** Returns a mapping from segment ordinals to global ordinals. */ public abstract LongUnaryOperator globalOrdinalsMapping(LeafReaderContext context) throws IOException; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorFactory.java index cfbea3010e6..54ef4dc0388 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorFactory.java @@ -42,19 +42,17 @@ public abstract class ValuesSourceAggregatorFactory extends AggregatorFactory { @Override public Aggregator createInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - ValuesSource vs = config.toValuesSource(); - if (vs == null) { + if (config.hasValues() == false) { return createUnmapped(searchContext, parent, metadata); } - return doCreateInternal(vs, searchContext, parent, collectsFromSingleBucket, metadata); + return doCreateInternal(searchContext, parent, collectsFromSingleBucket, metadata); } protected abstract Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map metadata) throws IOException; - protected abstract Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, + protected abstract Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java index 7357c266dfd..44c4535a40c 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java @@ -154,10 +154,18 @@ public class ValuesSourceConfig { if (valuesSourceType == null) { valuesSourceType = defaultValueSourceType; } - config = new ValuesSourceConfig(valuesSourceType, fieldContext, unmapped, aggregationScript, scriptValueType, context::nowInMillis); - config.format(resolveFormat(format, valuesSourceType, timeZone, fieldType)); - config.missing(missing); - config.timezone(timeZone); + DocValueFormat docValueFormat = resolveFormat(format, valuesSourceType, timeZone, fieldType); + config = new ValuesSourceConfig( + valuesSourceType, + fieldContext, + unmapped, + aggregationScript, + scriptValueType, + missing, + timeZone, + docValueFormat, + context::nowInMillis + ); return config; } @@ -231,6 +239,9 @@ public class ValuesSourceConfig { false, null, null, + null, + null, + null, queryShardContext::nowInMillis ); } @@ -239,19 +250,23 @@ public class ValuesSourceConfig { * Convenience method for creating unmapped configs */ public static ValuesSourceConfig resolveUnmapped(ValuesSourceType valuesSourceType, QueryShardContext queryShardContext) { - return new ValuesSourceConfig(valuesSourceType, null, true, null, null, queryShardContext::nowInMillis); + return new ValuesSourceConfig(valuesSourceType, null, true, null, null, null, null, null, queryShardContext::nowInMillis); } private final ValuesSourceType valuesSourceType; - private FieldContext fieldContext; - private AggregationScript.LeafFactory script; - private ValueType scriptValueType; - private boolean unmapped; - private DocValueFormat format = DocValueFormat.RAW; - private Object missing; - private ZoneId timeZone; - private LongSupplier nowSupplier; + private final FieldContext fieldContext; + private final AggregationScript.LeafFactory script; + private final ValueType scriptValueType; + private final boolean unmapped; + private final DocValueFormat format; + private final Object missing; + private final ZoneId timeZone; + private final LongSupplier nowSupplier; + private final ValuesSource valuesSource; + private ValuesSourceConfig() { + throw new UnsupportedOperationException(); + } public ValuesSourceConfig( ValuesSourceType valuesSourceType, @@ -259,6 +274,9 @@ public class ValuesSourceConfig { boolean unmapped, AggregationScript.LeafFactory script, ValueType scriptValueType, + Object missing, + ZoneId timeZone, + DocValueFormat format, LongSupplier nowSupplier ) { if (unmapped && fieldContext != null) { @@ -269,8 +287,38 @@ public class ValuesSourceConfig { this.unmapped = unmapped; this.script = script; this.scriptValueType = scriptValueType; + this.missing = missing; + this.timeZone = timeZone; + this.format = format == null ? DocValueFormat.RAW : format; this.nowSupplier = nowSupplier; + if (!valid()) { + // TODO: resolve no longer generates invalid configs. Once VSConfig is immutable, we can drop this check + throw new IllegalStateException( + "value source config is invalid; must have either a field context or a script or marked as unwrapped"); + } + valuesSource = ConstructValuesSource(missing, format, nowSupplier); + } + + private ValuesSource ConstructValuesSource(Object missing, DocValueFormat format, LongSupplier nowSupplier) { + final ValuesSource vs; + if (this.unmapped) { + vs = valueSourceType().getEmpty(); + } else { + if (fieldContext() == null) { + // Script case + vs = valueSourceType().getScript(script(), scriptValueType()); + } else { + // Field or Value Script case + vs = valueSourceType().getField(fieldContext(), script()); + } + } + + if (missing() != null) { + return valueSourceType().replaceMissing(vs, missing, format, nowSupplier); + } else { + return vs; + } } public ValuesSourceType valueSourceType() { @@ -285,8 +333,12 @@ public class ValuesSourceConfig { return script; } - public boolean unmapped() { - return unmapped; + /** + * Returns true if the values source configured by this object can yield values. We might not be able to yield values if, for example, + * the specified field does not exist on this index. + */ + public boolean hasValues() { + return fieldContext != null || script != null || missing != null; } public boolean valid() { @@ -297,25 +349,10 @@ public class ValuesSourceConfig { return this.scriptValueType; } - private ValuesSourceConfig format(final DocValueFormat format) { - this.format = format; - return this; - } - - private ValuesSourceConfig missing(final Object missing) { - this.missing = missing; - return this; - } - public Object missing() { return this.missing; } - private ValuesSourceConfig timezone(final ZoneId timeZone) { - this.timeZone = timeZone; - return this; - } - public ZoneId timezone() { return this.timeZone; } @@ -324,41 +361,11 @@ public class ValuesSourceConfig { return format; } - /** - * Transform the {@link ValuesSourceType} we selected in resolve into the specific {@link ValuesSource} instance to use for this shard - * @return - A {@link ValuesSource} ready to be read from by an aggregator - */ - @Nullable - public ValuesSource toValuesSource() { - if (!valid()) { - // TODO: resolve no longer generates invalid configs. Once VSConfig is immutable, we can drop this check - throw new IllegalStateException( - "value source config is invalid; must have either a field context or a script or marked as unwrapped"); - } + public ValuesSource getValuesSource() { + return valuesSource; + } - final ValuesSource vs; - if (unmapped()) { - if (missing() == null) { - /* Null values source signals to the AggregationBuilder to use the createUnmapped method, which aggregator factories can - * override to provide an aggregator optimized to return empty values - */ - vs = null; - } else { - vs = valueSourceType().getEmpty(); - } - } else { - if (fieldContext() == null) { - // Script case - vs = valueSourceType().getScript(script(), scriptValueType()); - } else { - // Field or Value Script case - vs = valueSourceType().getField(fieldContext(), script()); - } - } - - if (missing() == null) { - return vs; - } - return valueSourceType().replaceMissing(vs, missing, format, nowSupplier); + public boolean hasGlobalOrdinals() { + return valuesSource.hasGlobalOrdinals(); } } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/WeightedAvgAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/WeightedAvgAggregatorTests.java index 201aac012ca..d4360ce3905 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/WeightedAvgAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/WeightedAvgAggregatorTests.java @@ -83,6 +83,36 @@ public class WeightedAvgAggregatorTests extends AggregatorTestCase { }); } + public void testUnmappedWeight() throws IOException { + MultiValuesSourceFieldConfig valueConfig = new MultiValuesSourceFieldConfig.Builder().setFieldName("value_field").build(); + MultiValuesSourceFieldConfig weightConfig = new MultiValuesSourceFieldConfig.Builder().setFieldName("weight_field").build(); + WeightedAvgAggregationBuilder aggregationBuilder = new WeightedAvgAggregationBuilder("_name") + .value(valueConfig) + .weight(weightConfig); + testCase(new MatchAllDocsQuery(), aggregationBuilder, iw -> { + iw.addDocument(singleton(new SortedNumericDocValuesField("value_field", 7))); + iw.addDocument(singleton(new SortedNumericDocValuesField("value_field", 3))); + }, avg -> { + assertEquals(Double.NaN, avg.getValue(), 0); + assertFalse(AggregationInspectionHelper.hasValue(avg)); + }); + } + + public void testUnmappedValue() throws IOException { + MultiValuesSourceFieldConfig valueConfig = new MultiValuesSourceFieldConfig.Builder().setFieldName("value_field").build(); + MultiValuesSourceFieldConfig weightConfig = new MultiValuesSourceFieldConfig.Builder().setFieldName("weight_field").build(); + WeightedAvgAggregationBuilder aggregationBuilder = new WeightedAvgAggregationBuilder("_name") + .value(valueConfig) + .weight(weightConfig); + testCase(new MatchAllDocsQuery(), aggregationBuilder, iw -> { + iw.addDocument(singleton(new SortedNumericDocValuesField("weight_field", 7))); + iw.addDocument(singleton(new SortedNumericDocValuesField("weight_field", 3))); + }, avg -> { + assertEquals(Double.NaN, avg.getValue(), 0); + assertFalse(AggregationInspectionHelper.hasValue(avg)); + }); + } + public void testSomeMatchesSortedNumericDocValuesNoWeight() throws IOException { MultiValuesSourceFieldConfig valueConfig = new MultiValuesSourceFieldConfig.Builder().setFieldName("value_field").build(); MultiValuesSourceFieldConfig weightConfig = new MultiValuesSourceFieldConfig.Builder().setFieldName("weight_field").build(); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java index 44e097a3244..a2083b6ad59 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java @@ -47,7 +47,7 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase { ValuesSourceConfig config = ValuesSourceConfig.resolve( context, null, "bytes", null, null, null, null, CoreValuesSourceType.BYTES, null); - ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(); + ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.getValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedBinaryDocValues values = valuesSource.bytesValues(ctx); assertTrue(values.advanceExact(0)); @@ -69,14 +69,14 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase { ValuesSourceConfig config = ValuesSourceConfig.resolve( context, null, "bytes", null, null, null, null, CoreValuesSourceType.BYTES, null); - ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(); + ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.getValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedBinaryDocValues values = valuesSource.bytesValues(ctx); assertFalse(values.advanceExact(0)); config = ValuesSourceConfig.resolve( context, null, "bytes", null, "abc", null, null, CoreValuesSourceType.BYTES, null); - valuesSource = (ValuesSource.Bytes) config.toValuesSource(); + valuesSource = (ValuesSource.Bytes) config.getValuesSource(); values = valuesSource.bytesValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); @@ -95,12 +95,13 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( context, ValueType.STRING, "bytes", null, null, null, null, CoreValuesSourceType.BYTES, null); - ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(); - assertNull(valuesSource); + ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.getValuesSource(); + assertNotNull(valuesSource); + assertFalse(config.hasValues()); config = ValuesSourceConfig.resolve( context, ValueType.STRING, "bytes", null, "abc", null, null, CoreValuesSourceType.BYTES, null); - valuesSource = (ValuesSource.Bytes) config.toValuesSource(); + valuesSource = (ValuesSource.Bytes) config.getValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedBinaryDocValues values = valuesSource.bytesValues(ctx); assertTrue(values.advanceExact(0)); @@ -122,7 +123,7 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase { ValuesSourceConfig config = ValuesSourceConfig.resolve( context, null, "long", null, null, null, null, CoreValuesSourceType.BYTES, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); @@ -144,14 +145,14 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase { ValuesSourceConfig config = ValuesSourceConfig.resolve( context, null, "long", null, null, null, null, CoreValuesSourceType.BYTES, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertFalse(values.advanceExact(0)); config = ValuesSourceConfig.resolve( context, null, "long", null, 42, null, null, CoreValuesSourceType.BYTES, null); - valuesSource = (ValuesSource.Numeric) config.toValuesSource(); + valuesSource = (ValuesSource.Numeric) config.getValuesSource(); values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); @@ -171,12 +172,13 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase { ValuesSourceConfig config = ValuesSourceConfig.resolve( context, ValueType.NUMBER, "long", null, null, null, null, CoreValuesSourceType.BYTES, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); - assertNull(valuesSource); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); + assertNotNull(valuesSource); + assertFalse(config.hasValues()); config = ValuesSourceConfig.resolve( context, ValueType.NUMBER, "long", null, 42, null, null, CoreValuesSourceType.BYTES, null); - valuesSource = (ValuesSource.Numeric) config.toValuesSource(); + valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); @@ -198,7 +200,7 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase { ValuesSourceConfig config = ValuesSourceConfig.resolve( context, null, "bool", null, null, null, null, CoreValuesSourceType.BYTES, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); @@ -220,14 +222,14 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase { ValuesSourceConfig config = ValuesSourceConfig.resolve( context, null, "bool", null, null, null, null, CoreValuesSourceType.BYTES, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertFalse(values.advanceExact(0)); config = ValuesSourceConfig.resolve( context, null, "bool", null, true, null, null, CoreValuesSourceType.BYTES, null); - valuesSource = (ValuesSource.Numeric) config.toValuesSource(); + valuesSource = (ValuesSource.Numeric) config.getValuesSource(); values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); @@ -247,12 +249,13 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase { ValuesSourceConfig config = ValuesSourceConfig.resolve( context, ValueType.BOOLEAN, "bool", null, null, null, null, CoreValuesSourceType.BYTES, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); - assertNull(valuesSource); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); + assertNotNull(valuesSource); + assertFalse(config.hasValues()); config = ValuesSourceConfig.resolve( context, ValueType.BOOLEAN, "bool", null, true, null, null, CoreValuesSourceType.BYTES, null); - valuesSource = (ValuesSource.Numeric) config.toValuesSource(); + valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); @@ -284,7 +287,7 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( context, ValueType.STRING, "alias", null, null, null, null, CoreValuesSourceType.BYTES, null); - ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(); + ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.getValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedBinaryDocValues values = valuesSource.bytesValues(ctx); diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/AnalyticsAggregatorFactory.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/AnalyticsAggregatorFactory.java index 978fa5ec803..24e25793c58 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/AnalyticsAggregatorFactory.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/AnalyticsAggregatorFactory.java @@ -14,10 +14,8 @@ import org.elasticsearch.search.aggregations.metrics.PercentilesConfig; import org.elasticsearch.search.aggregations.metrics.PercentilesMethod; import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.ValueCountAggregatorSupplier; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; import org.elasticsearch.xpack.analytics.aggregations.support.AnalyticsValuesSourceType; -import org.elasticsearch.xpack.analytics.aggregations.support.HistogramValuesSource; public class AnalyticsAggregatorFactory { @@ -68,36 +66,21 @@ public class AnalyticsAggregatorFactory { public static void registerHistoBackedSumAggregator(ValuesSourceRegistry.Builder builder) { builder.register(SumAggregationBuilder.NAME, AnalyticsValuesSourceType.HISTOGRAM, - (MetricAggregatorSupplier) (name, valuesSourceConfig, valuesSource, context, parent, metadata) -> new HistoBackedSumAggregator( - name, - (HistogramValuesSource.Histogram) valuesSource, - valuesSourceConfig.format(), - context, - parent, - metadata - ) + (MetricAggregatorSupplier) HistoBackedSumAggregator::new ); } public static void registerHistoBackedValueCountAggregator(ValuesSourceRegistry.Builder builder) { builder.register(ValueCountAggregationBuilder.NAME, AnalyticsValuesSourceType.HISTOGRAM, - (ValueCountAggregatorSupplier) (name, valuesSource, context, parent, metadata) -> - new HistoBackedValueCountAggregator(name, (HistogramValuesSource.Histogram) valuesSource, context, parent, metadata) + (MetricAggregatorSupplier) HistoBackedValueCountAggregator::new ); } public static void registerHistoBackedAverageAggregator(ValuesSourceRegistry.Builder builder) { builder.register(AvgAggregationBuilder.NAME, AnalyticsValuesSourceType.HISTOGRAM, - (MetricAggregatorSupplier) (name, valuesSourceConfig, valuesSource, context, parent, metadata) -> new HistoBackedAvgAggregator( - name, - (HistogramValuesSource.Histogram) valuesSource, - valuesSourceConfig.format(), - context, - parent, - metadata - ) + (MetricAggregatorSupplier) HistoBackedAvgAggregator::new ); } } diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedAvgAggregator.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedAvgAggregator.java index 3e312ef9693..424c17e4f91 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedAvgAggregator.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedAvgAggregator.java @@ -21,6 +21,7 @@ import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.metrics.CompensatedSum; import org.elasticsearch.search.aggregations.metrics.InternalAvg; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.xpack.analytics.aggregations.support.HistogramValuesSource; @@ -40,11 +41,17 @@ class HistoBackedAvgAggregator extends NumericMetricsAggregator.SingleValue { DoubleArray compensations; DocValueFormat format; - HistoBackedAvgAggregator(String name, HistogramValuesSource.Histogram valuesSource, DocValueFormat formatter, SearchContext context, - Aggregator parent, Map metadata) throws IOException { + HistoBackedAvgAggregator( + String name, + ValuesSourceConfig valuesSourceConfig, + SearchContext context, + Aggregator parent, + Map metadata + ) throws IOException { super(name, context, parent, metadata); - this.valuesSource = valuesSource; - this.format = formatter; + // TODO: Stop depending on nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? (HistogramValuesSource.Histogram) valuesSourceConfig.getValuesSource() : null; + this.format = valuesSourceConfig.format(); if (valuesSource != null) { final BigArrays bigArrays = context.bigArrays(); counts = bigArrays.newLongArray(1, true); diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedSumAggregator.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedSumAggregator.java index 4060f6b4858..662c21a6bf2 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedSumAggregator.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedSumAggregator.java @@ -20,6 +20,7 @@ import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.metrics.CompensatedSum; import org.elasticsearch.search.aggregations.metrics.InternalSum; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.xpack.analytics.aggregations.support.HistogramValuesSource; @@ -40,11 +41,17 @@ class HistoBackedSumAggregator extends NumericMetricsAggregator.SingleValue { private DoubleArray sums; private DoubleArray compensations; - HistoBackedSumAggregator(String name, HistogramValuesSource.Histogram valuesSource, DocValueFormat formatter, SearchContext context, - Aggregator parent, Map metadata) throws IOException { + HistoBackedSumAggregator( + String name, + ValuesSourceConfig valuesSourceConfig, + SearchContext context, + Aggregator parent, + Map metadata + ) throws IOException { super(name, context, parent, metadata); - this.valuesSource = valuesSource; - this.format = formatter; + // TODO: stop expecting a null here + this.valuesSource = valuesSourceConfig.hasValues() ? (HistogramValuesSource.Histogram) valuesSourceConfig.getValuesSource() : null; + this.format = valuesSourceConfig.format(); if (valuesSource != null) { sums = context.bigArrays().newDoubleArray(1, true); compensations = context.bigArrays().newDoubleArray(1, true); diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedValueCountAggregator.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedValueCountAggregator.java index 2cf5627f3bc..2b5af2a1d55 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedValueCountAggregator.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/aggregations/metrics/HistoBackedValueCountAggregator.java @@ -17,6 +17,7 @@ import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.metrics.InternalValueCount; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.xpack.analytics.aggregations.support.HistogramValuesSource; @@ -37,12 +38,13 @@ public class HistoBackedValueCountAggregator extends NumericMetricsAggregator.Si public HistoBackedValueCountAggregator( String name, - HistogramValuesSource.Histogram valuesSource, + ValuesSourceConfig valuesSourceConfig, SearchContext aggregationContext, Aggregator parent, Map metadata) throws IOException { super(name, aggregationContext, parent, metadata); - this.valuesSource = valuesSource; + // TODO: stop using nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? (HistogramValuesSource.Histogram) valuesSourceConfig.getValuesSource() : null; if (valuesSource != null) { counts = context.bigArrays().newLongArray(1, true); } diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregatorFactory.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregatorFactory.java index c9819b032fb..46146af69c8 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregatorFactory.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregatorFactory.java @@ -13,7 +13,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -54,8 +53,7 @@ public class BoxplotAggregatorFactory extends ValuesSourceAggregatorFactory { } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, + protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { @@ -66,7 +64,7 @@ public class BoxplotAggregatorFactory extends ValuesSourceAggregatorFactory { throw new AggregationExecutionException("Registry miss-match - expected BoxplotAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((BoxplotAggregatorSupplier) aggregatorSupplier).build(name, valuesSource, config.format(), compression, + return ((BoxplotAggregatorSupplier) aggregatorSupplier).build(name, config.getValuesSource(), config.format(), compression, searchContext, parent, metadata); } } diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/stringstats/StringStatsAggregatorFactory.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/stringstats/StringStatsAggregatorFactory.java index a79b1c3dbfa..926d331d065 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/stringstats/StringStatsAggregatorFactory.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/stringstats/StringStatsAggregatorFactory.java @@ -13,7 +13,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregatorSupplier; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; @@ -48,8 +47,7 @@ class StringStatsAggregatorFactory extends ValuesSourceAggregatorFactory { } @Override - protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, + protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { @@ -60,7 +58,7 @@ class StringStatsAggregatorFactory extends ValuesSourceAggregatorFactory { throw new AggregationExecutionException("Registry miss-match - expected StringStatsAggregatorSupplier, found [" + aggregatorSupplier.getClass().toString() + "]"); } - return ((StringStatsAggregatorSupplier) aggregatorSupplier).build(name, valuesSource, showDistribution, config.format(), + return ((StringStatsAggregatorSupplier) aggregatorSupplier).build(name, config.getValuesSource(), showDistribution, config.format(), searchContext, parent, metadata); } diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorFactory.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorFactory.java index b36dafaa8ce..71ed774cdec 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorFactory.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorFactory.java @@ -63,7 +63,7 @@ public class TopMetricsAggregatorFactory extends AggregatorFactory { config.getFieldName(), config.getScript(), config.getMissing(), config.getTimeZone(), null, CoreValuesSourceType.NUMERIC, TopMetricsAggregationBuilder.NAME); return new TopMetricsAggregator.MetricSource(config.getFieldName(), resolved.format(), - (ValuesSource.Numeric) resolved.toValuesSource()); + (ValuesSource.Numeric) resolved.getValuesSource()); }).collect(toList()); return new TopMetricsAggregator(name, searchContext, parent, metadata, size, sortBuilders.get(0), metricSources); } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java index 66766d98b94..20982a0f38e 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java @@ -22,11 +22,10 @@ import org.elasticsearch.search.aggregations.metrics.CardinalityAggregatorSuppli import org.elasticsearch.search.aggregations.metrics.GeoBoundsAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.GeoBoundsAggregatorSupplier; import org.elasticsearch.search.aggregations.metrics.GeoCentroidAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.GeoCentroidAggregatorSupplier; import org.elasticsearch.search.aggregations.metrics.GeoGridAggregatorSupplier; +import org.elasticsearch.search.aggregations.metrics.MetricAggregatorSupplier; import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.ValueCountAggregator; -import org.elasticsearch.search.aggregations.metrics.ValueCountAggregatorSupplier; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.spatial.aggregations.metrics.GeoShapeCentroidAggregator; @@ -101,17 +100,15 @@ public class SpatialPlugin extends GeoPlugin implements MapperPlugin, SearchPlug private static void registerGeoShapeBoundsAggregator(ValuesSourceRegistry.Builder builder) { builder.register(GeoBoundsAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(), - (GeoBoundsAggregatorSupplier) (name, aggregationContext, parent, valuesSource, wrapLongitude, metadata) - -> new GeoShapeBoundsAggregator(name, aggregationContext, parent, (GeoShapeValuesSource) valuesSource, - wrapLongitude, metadata)); + (GeoBoundsAggregatorSupplier) GeoShapeBoundsAggregator::new); } private void registerGeoShapeCentroidAggregator(ValuesSourceRegistry.Builder builder) { builder.register(GeoCentroidAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(), - (GeoCentroidAggregatorSupplier) (name, aggregationContext, parent, valuesSource, metadata) + (MetricAggregatorSupplier) (name, valuesSourceConfig, aggregationContext, parent, metadata) -> { if (getLicenseState().isAllowed(XPackLicenseState.Feature.SPATIAL_GEO_CENTROID)) { - return new GeoShapeCentroidAggregator(name, aggregationContext, parent, (GeoShapeValuesSource) valuesSource, metadata); + return new GeoShapeCentroidAggregator(name, aggregationContext, parent, valuesSourceConfig, metadata); } throw LicenseUtils.newComplianceException("geo_centroid aggregation on geo_shape fields"); }); @@ -161,7 +158,7 @@ public class SpatialPlugin extends GeoPlugin implements MapperPlugin, SearchPlug private static void registerValueCountAggregator(ValuesSourceRegistry.Builder builder) { builder.register(ValueCountAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(), - (ValueCountAggregatorSupplier) ValueCountAggregator::new + (MetricAggregatorSupplier) ValueCountAggregator::new ); } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/aggregations/metrics/GeoShapeCentroidAggregator.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/aggregations/metrics/GeoShapeCentroidAggregator.java index d92b1a155c8..86e2afb2a94 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/aggregations/metrics/GeoShapeCentroidAggregator.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/aggregations/metrics/GeoShapeCentroidAggregator.java @@ -21,6 +21,7 @@ import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.metrics.CompensatedSum; import org.elasticsearch.search.aggregations.metrics.InternalGeoCentroid; import org.elasticsearch.search.aggregations.metrics.MetricsAggregator; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.xpack.spatial.index.fielddata.DimensionalShapeType; import org.elasticsearch.xpack.spatial.index.fielddata.MultiGeoShapeValues; @@ -38,10 +39,16 @@ public final class GeoShapeCentroidAggregator extends MetricsAggregator { private LongArray counts; private ByteArray dimensionalShapeTypes; - public GeoShapeCentroidAggregator(String name, SearchContext context, Aggregator parent, - GeoShapeValuesSource valuesSource, Map metadata) throws IOException { + public GeoShapeCentroidAggregator( + String name, + SearchContext context, + Aggregator parent, + ValuesSourceConfig valuesSourceConfig, + Map metadata + ) throws IOException { super(name, context, parent, metadata); - this.valuesSource = valuesSource; + // TODO: stop expecting nulls here + this.valuesSource = valuesSourceConfig.hasValues() ? (GeoShapeValuesSource) valuesSourceConfig.getValuesSource() : null; if (valuesSource != null) { final BigArrays bigArrays = context.bigArrays(); lonSum = bigArrays.newDoubleArray(1, true); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java index 4a22f80784f..9ce6dc800d6 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java @@ -16,6 +16,7 @@ import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.metrics.InternalGeoBounds; import org.elasticsearch.search.aggregations.metrics.MetricsAggregator; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.xpack.spatial.index.fielddata.MultiGeoShapeValues; import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSource; @@ -33,10 +34,16 @@ public final class GeoShapeBoundsAggregator extends MetricsAggregator { private DoubleArray negLefts; private DoubleArray negRights; - public GeoShapeBoundsAggregator(String name, SearchContext aggregationContext, Aggregator parent, - GeoShapeValuesSource valuesSource, boolean wrapLongitude, Map metadata) throws IOException { + public GeoShapeBoundsAggregator( + String name, + SearchContext aggregationContext, + Aggregator parent, + ValuesSourceConfig valuesSourceConfig, + boolean wrapLongitude, + Map metadata + ) throws IOException { super(name, aggregationContext, parent, metadata); - this.valuesSource = valuesSource; + this.valuesSource = valuesSourceConfig.hasValues() ? (GeoShapeValuesSource) valuesSourceConfig.getValuesSource() : null; this.wrapLongitude = wrapLongitude; if (valuesSource != null) { final BigArrays bigArrays = context.bigArrays(); diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java index f9d11c9f56e..4b691df5651 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java @@ -12,8 +12,8 @@ import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileGridAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.GeoCentroidAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.GeoCentroidAggregatorSupplier; import org.elasticsearch.search.aggregations.metrics.GeoGridAggregatorSupplier; +import org.elasticsearch.search.aggregations.metrics.MetricAggregatorSupplier; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; import org.elasticsearch.test.ESTestCase; @@ -35,8 +35,8 @@ public class SpatialPluginTests extends ESTestCase { List> registrar = plugin.getAggregationExtentions(); registrar.forEach(c -> c.accept(registryBuilder)); ValuesSourceRegistry registry = registryBuilder.build(); - GeoCentroidAggregatorSupplier centroidSupplier = (GeoCentroidAggregatorSupplier) registry.getAggregator( - new ValuesSourceConfig(GeoShapeValuesSourceType.instance(), null, false, null, null, null), + MetricAggregatorSupplier centroidSupplier = (MetricAggregatorSupplier) registry.getAggregator( + new ValuesSourceConfig(GeoShapeValuesSourceType.instance(), null, true, null, null, null, null, null, null), GeoCentroidAggregationBuilder.NAME); if (License.OperationMode.TRIAL != operationMode && License.OperationMode.compare(operationMode, License.OperationMode.GOLD) < 0) { @@ -57,7 +57,7 @@ public class SpatialPluginTests extends ESTestCase { registrar.forEach(c -> c.accept(registryBuilder)); ValuesSourceRegistry registry = registryBuilder.build(); GeoGridAggregatorSupplier supplier = (GeoGridAggregatorSupplier) registry.getAggregator( - new ValuesSourceConfig(GeoShapeValuesSourceType.instance(), null, false, null, null, null), + new ValuesSourceConfig(GeoShapeValuesSourceType.instance(), null, true, null, null, null, null, null, null), builderName); if (License.OperationMode.TRIAL != operationMode && License.OperationMode.compare(operationMode, License.OperationMode.GOLD) < 0) {