parent
d26a3e144e
commit
db1df6cc30
|
@ -33,6 +33,7 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
|||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
|
||||
|
@ -79,6 +80,12 @@ public class StringStatsAggregationBuilder extends ValuesSourceAggregationBuilde
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
// This would be called from the same thing that calls innerBuild, which also throws. So it's "safe" to throw here.
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.field(StringStatsAggregationBuilder.SHOW_DISTRIBUTION_FIELD.getPreferredName(), showDistribution);
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
|||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -186,4 +187,9 @@ public class ChildrenAggregationBuilder extends ValuesSourceAggregationBuilder<C
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return ValuesSourceRegistry.UNREGISTERED_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,14 +36,14 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
|||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ParentAggregationBuilder
|
||||
extends ValuesSourceAggregationBuilder<ParentAggregationBuilder> {
|
||||
public class ParentAggregationBuilder extends ValuesSourceAggregationBuilder<ParentAggregationBuilder> {
|
||||
|
||||
public static final String NAME = "parent";
|
||||
|
||||
|
@ -179,4 +179,9 @@ public class ParentAggregationBuilder
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return ValuesSourceRegistry.UNREGISTERED_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ import java.util.function.LongConsumer;
|
|||
public class DateHistogramValuesSourceBuilder
|
||||
extends CompositeValuesSourceBuilder<DateHistogramValuesSourceBuilder> implements DateIntervalConsumer {
|
||||
@FunctionalInterface
|
||||
public interface DateHistogramCompositeSupplier extends ValuesSourceRegistry.CompositeSupplier {
|
||||
public interface DateHistogramCompositeSupplier {
|
||||
CompositeValuesSourceConfig apply(
|
||||
ValuesSourceConfig config,
|
||||
Rounding rounding,
|
||||
|
@ -270,7 +270,7 @@ public class DateHistogramValuesSourceBuilder
|
|||
}
|
||||
|
||||
public static void register(ValuesSourceRegistry.Builder builder) {
|
||||
builder.registerComposite(
|
||||
builder.register(
|
||||
REGISTRY_KEY,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.DATE, CoreValuesSourceType.NUMERIC),
|
||||
(valuesSourceConfig, rounding, name, hasScript, format, missingBucket, order) -> {
|
||||
|
@ -309,8 +309,8 @@ public class DateHistogramValuesSourceBuilder
|
|||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -322,7 +322,7 @@ public class DateHistogramValuesSourceBuilder
|
|||
protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException {
|
||||
Rounding rounding = dateHistogramInterval.createRounding(timeZone(), offset);
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getComposite(REGISTRY_KEY, config)
|
||||
.getAggregator(REGISTRY_KEY, config)
|
||||
.apply(config, rounding, name, config.script() != null, format(), missingBucket(), order());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ import java.util.function.LongUnaryOperator;
|
|||
|
||||
public class GeoTileGridValuesSourceBuilder extends CompositeValuesSourceBuilder<GeoTileGridValuesSourceBuilder> {
|
||||
@FunctionalInterface
|
||||
public interface GeoTileCompositeSuppier extends ValuesSourceRegistry.CompositeSupplier {
|
||||
public interface GeoTileCompositeSuppier {
|
||||
CompositeValuesSourceConfig apply(
|
||||
ValuesSourceConfig config,
|
||||
int precision,
|
||||
|
@ -84,7 +84,7 @@ public class GeoTileGridValuesSourceBuilder extends CompositeValuesSourceBuilder
|
|||
|
||||
static void register(ValuesSourceRegistry.Builder builder) {
|
||||
|
||||
builder.registerComposite(
|
||||
builder.register(
|
||||
REGISTRY_KEY,
|
||||
CoreValuesSourceType.GEOPOINT,
|
||||
(valuesSourceConfig, precision, boundingBox, name, hasScript, format, missingBucket, order) -> {
|
||||
|
@ -126,8 +126,8 @@ public class GeoTileGridValuesSourceBuilder extends CompositeValuesSourceBuilder
|
|||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
private int precision = GeoTileGridAggregationBuilder.DEFAULT_PRECISION;
|
||||
|
@ -208,7 +208,7 @@ public class GeoTileGridValuesSourceBuilder extends CompositeValuesSourceBuilder
|
|||
@Override
|
||||
protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getComposite(REGISTRY_KEY, config)
|
||||
.getAggregator(REGISTRY_KEY, config)
|
||||
.apply(config, precision, geoBoundingBox(), name, script() != null, format(), missingBucket(), order());
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ import java.util.function.LongConsumer;
|
|||
*/
|
||||
public class HistogramValuesSourceBuilder extends CompositeValuesSourceBuilder<HistogramValuesSourceBuilder> {
|
||||
@FunctionalInterface
|
||||
public interface HistogramCompositeSupplier extends ValuesSourceRegistry.CompositeSupplier {
|
||||
public interface HistogramCompositeSupplier {
|
||||
CompositeValuesSourceConfig apply(
|
||||
ValuesSourceConfig config,
|
||||
double interval,
|
||||
|
@ -75,7 +75,7 @@ public class HistogramValuesSourceBuilder extends CompositeValuesSourceBuilder<H
|
|||
}
|
||||
|
||||
public static void register(ValuesSourceRegistry.Builder builder) {
|
||||
builder.registerComposite(
|
||||
builder.register(
|
||||
REGISTRY_KEY,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.DATE, CoreValuesSourceType.NUMERIC),
|
||||
(valuesSourceConfig, interval, name, hasScript, format, missingBucket, order) -> {
|
||||
|
@ -108,7 +108,7 @@ public class HistogramValuesSourceBuilder extends CompositeValuesSourceBuilder<H
|
|||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
}, false);
|
||||
}
|
||||
|
||||
private double interval = 0;
|
||||
|
@ -177,7 +177,7 @@ public class HistogramValuesSourceBuilder extends CompositeValuesSourceBuilder<H
|
|||
@Override
|
||||
protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getComposite(REGISTRY_KEY, config)
|
||||
.getAggregator(REGISTRY_KEY, config)
|
||||
.apply(config, interval, name, script() != null, format(), missingBucket(), order());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ import java.util.function.LongUnaryOperator;
|
|||
public class TermsValuesSourceBuilder extends CompositeValuesSourceBuilder<TermsValuesSourceBuilder> {
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TermsCompositeSupplier extends ValuesSourceRegistry.CompositeSupplier {
|
||||
public interface TermsCompositeSupplier {
|
||||
CompositeValuesSourceConfig apply(
|
||||
ValuesSourceConfig config,
|
||||
String name,
|
||||
|
@ -94,7 +94,7 @@ public class TermsValuesSourceBuilder extends CompositeValuesSourceBuilder<Terms
|
|||
}
|
||||
|
||||
static void register(ValuesSourceRegistry.Builder builder) {
|
||||
builder.registerComposite(
|
||||
builder.register(
|
||||
REGISTRY_KEY,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.DATE, CoreValuesSourceType.NUMERIC, CoreValuesSourceType.BOOLEAN),
|
||||
(valuesSourceConfig, name, hasScript, format, missingBucket, order) -> {
|
||||
|
@ -149,10 +149,10 @@ public class TermsValuesSourceBuilder extends CompositeValuesSourceBuilder<Terms
|
|||
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
false);
|
||||
|
||||
builder.registerComposite(
|
||||
builder.register(
|
||||
REGISTRY_KEY,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.BYTES, CoreValuesSourceType.IP),
|
||||
(valuesSourceConfig, name, hasScript, format, missingBucket, order) -> new CompositeValuesSourceConfig(
|
||||
|
@ -196,8 +196,8 @@ public class TermsValuesSourceBuilder extends CompositeValuesSourceBuilder<Terms
|
|||
);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
),
|
||||
false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -208,7 +208,7 @@ public class TermsValuesSourceBuilder extends CompositeValuesSourceBuilder<Terms
|
|||
@Override
|
||||
protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getComposite(REGISTRY_KEY, config)
|
||||
.getAggregator(REGISTRY_KEY, config)
|
||||
.apply(config, name, script() != null, format(), missingBucket(), order());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.index.query.QueryShardContext;
|
|||
import org.elasticsearch.search.aggregations.AggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.metrics.GeoGridAggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
|
||||
|
@ -38,6 +39,10 @@ public class GeoHashGridAggregationBuilder extends GeoGridAggregationBuilder {
|
|||
public static final String NAME = "geohash_grid";
|
||||
public static final int DEFAULT_PRECISION = 5;
|
||||
public static final int DEFAULT_MAX_NUM_CELLS = 10000;
|
||||
public static final ValuesSourceRegistry.RegistryKey<GeoGridAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
GeoGridAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<GeoHashGridAggregationBuilder, String> PARSER =
|
||||
createParser(NAME, GeoUtils::parsePrecision, GeoHashGridAggregationBuilder::new);
|
||||
|
@ -87,4 +92,9 @@ public class GeoHashGridAggregationBuilder extends GeoGridAggregationBuilder {
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,15 +22,12 @@ package org.elasticsearch.search.aggregations.bucket.geogrid;
|
|||
import org.elasticsearch.common.geo.GeoBoundingBox;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.InternalAggregation;
|
||||
import org.elasticsearch.search.aggregations.NonCollectingAggregator;
|
||||
import org.elasticsearch.search.aggregations.metrics.GeoGridAggregatorSupplier;
|
||||
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;
|
||||
|
@ -79,24 +76,57 @@ public class GeoHashGridAggregatorFactory extends ValuesSourceAggregatorFactory
|
|||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> 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, config.getValuesSource(), precision, geoBoundingBox,
|
||||
requiredSize, shardSize, searchContext, parent, cardinality, metadata);
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(GeoHashGridAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(
|
||||
name,
|
||||
factories,
|
||||
config.getValuesSource(),
|
||||
precision,
|
||||
geoBoundingBox,
|
||||
requiredSize,
|
||||
shardSize,
|
||||
searchContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
}
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(GeoHashGridAggregationBuilder.NAME, CoreValuesSourceType.GEOPOINT,
|
||||
(GeoGridAggregatorSupplier) (name, factories, valuesSource, precision, geoBoundingBox, requiredSize, shardSize,
|
||||
aggregationContext, parent, cardinality, metadata) -> {
|
||||
CellIdSource cellIdSource = new CellIdSource((ValuesSource.GeoPoint) valuesSource, precision, geoBoundingBox,
|
||||
Geohash::longEncode);
|
||||
return new GeoHashGridAggregator(name, factories, cellIdSource, requiredSize, shardSize, aggregationContext,
|
||||
parent, cardinality, metadata);
|
||||
});
|
||||
builder.register(
|
||||
GeoHashGridAggregationBuilder.REGISTRY_KEY,
|
||||
CoreValuesSourceType.GEOPOINT,
|
||||
(
|
||||
name,
|
||||
factories,
|
||||
valuesSource,
|
||||
precision,
|
||||
geoBoundingBox,
|
||||
requiredSize,
|
||||
shardSize,
|
||||
aggregationContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata) -> {
|
||||
CellIdSource cellIdSource = new CellIdSource(
|
||||
(ValuesSource.GeoPoint) valuesSource,
|
||||
precision,
|
||||
geoBoundingBox,
|
||||
Geohash::longEncode
|
||||
);
|
||||
return new GeoHashGridAggregator(
|
||||
name,
|
||||
factories,
|
||||
cellIdSource,
|
||||
requiredSize,
|
||||
shardSize,
|
||||
aggregationContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
},
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
|
||||
package org.elasticsearch.search.aggregations.bucket.geogrid;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.common.geo.GeoBoundingBox;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
|
@ -29,14 +26,22 @@ import org.elasticsearch.index.query.QueryShardContext;
|
|||
import org.elasticsearch.search.aggregations.AggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.metrics.GeoGridAggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeoTileGridAggregationBuilder extends GeoGridAggregationBuilder {
|
||||
public static final String NAME = "geotile_grid";
|
||||
public static final int DEFAULT_PRECISION = 7;
|
||||
private static final int DEFAULT_MAX_NUM_CELLS = 10000;
|
||||
public static final ValuesSourceRegistry.RegistryKey<GeoGridAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
GeoGridAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<GeoTileGridAggregationBuilder, String> PARSER =
|
||||
createParser(NAME, GeoTileUtils::parsePrecision, GeoTileGridAggregationBuilder::new);
|
||||
|
@ -85,4 +90,9 @@ public class GeoTileGridAggregationBuilder extends GeoGridAggregationBuilder {
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,15 +21,12 @@ package org.elasticsearch.search.aggregations.bucket.geogrid;
|
|||
|
||||
import org.elasticsearch.common.geo.GeoBoundingBox;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.InternalAggregation;
|
||||
import org.elasticsearch.search.aggregations.NonCollectingAggregator;
|
||||
import org.elasticsearch.search.aggregations.metrics.GeoGridAggregatorSupplier;
|
||||
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;
|
||||
|
@ -77,24 +74,51 @@ public class GeoTileGridAggregatorFactory extends ValuesSourceAggregatorFactory
|
|||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> 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, config.getValuesSource(), precision, geoBoundingBox,
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(GeoTileGridAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(
|
||||
name,
|
||||
factories,
|
||||
config.getValuesSource(),
|
||||
precision,
|
||||
geoBoundingBox,
|
||||
requiredSize, shardSize, searchContext, parent, cardinality, metadata);
|
||||
}
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(GeoTileGridAggregationBuilder.NAME, CoreValuesSourceType.GEOPOINT,
|
||||
(GeoGridAggregatorSupplier) (name, factories, valuesSource, precision, geoBoundingBox, requiredSize, shardSize,
|
||||
aggregationContext, parent, cardinality, metadata) -> {
|
||||
CellIdSource cellIdSource = new CellIdSource((ValuesSource.GeoPoint) valuesSource, precision, geoBoundingBox,
|
||||
GeoTileUtils::longEncode);
|
||||
return new GeoTileGridAggregator(name, factories, cellIdSource, requiredSize, shardSize, aggregationContext,
|
||||
parent, cardinality, metadata);
|
||||
});
|
||||
builder.register(
|
||||
GeoTileGridAggregationBuilder.REGISTRY_KEY,
|
||||
CoreValuesSourceType.GEOPOINT,
|
||||
(
|
||||
name,
|
||||
factories,
|
||||
valuesSource,
|
||||
precision,
|
||||
geoBoundingBox,
|
||||
requiredSize,
|
||||
shardSize,
|
||||
aggregationContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata) -> {
|
||||
CellIdSource cellIdSource = new CellIdSource(
|
||||
(ValuesSource.GeoPoint) valuesSource,
|
||||
precision,
|
||||
geoBoundingBox,
|
||||
GeoTileUtils::longEncode
|
||||
);
|
||||
return new GeoTileGridAggregator(
|
||||
name,
|
||||
factories,
|
||||
cellIdSource,
|
||||
requiredSize,
|
||||
shardSize,
|
||||
aggregationContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
},
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,10 +47,11 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AutoDateHistogramAggregationBuilder
|
||||
extends ValuesSourceAggregationBuilder<AutoDateHistogramAggregationBuilder> {
|
||||
public class AutoDateHistogramAggregationBuilder extends ValuesSourceAggregationBuilder<AutoDateHistogramAggregationBuilder> {
|
||||
|
||||
public static final String NAME = "auto_date_histogram";
|
||||
public static final ValuesSourceRegistry.RegistryKey<AutoDateHistogramAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, AutoDateHistogramAggregatorSupplier.class);
|
||||
|
||||
private static final ParseField NUM_BUCKETS_FIELD = new ParseField("buckets");
|
||||
private static final ParseField MINIMUM_INTERVAL_FIELD = new ParseField("minimum_interval");
|
||||
|
@ -159,6 +160,11 @@ public class AutoDateHistogramAggregationBuilder
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
|
||||
public String getMinimumIntervalExpression() {
|
||||
return minimumIntervalExpression;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,11 @@ package org.elasticsearch.search.aggregations.bucket.histogram;
|
|||
|
||||
import org.elasticsearch.common.Rounding;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
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.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -42,9 +40,11 @@ import java.util.function.Function;
|
|||
public final class AutoDateHistogramAggregatorFactory extends ValuesSourceAggregatorFactory {
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(AutoDateHistogramAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
AutoDateHistogramAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.DATE, CoreValuesSourceType.NUMERIC, CoreValuesSourceType.BOOLEAN),
|
||||
(AutoDateHistogramAggregatorSupplier) AutoDateHistogramAggregator::build);
|
||||
AutoDateHistogramAggregator::build,
|
||||
true);
|
||||
}
|
||||
|
||||
private final int numBuckets;
|
||||
|
@ -68,16 +68,22 @@ public final class AutoDateHistogramAggregatorFactory extends ValuesSourceAggreg
|
|||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
AutoDateHistogramAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof AutoDateHistogramAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected AutoDateHistogramAggregationSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
AutoDateHistogramAggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(AutoDateHistogramAggregationBuilder.REGISTRY_KEY, config);
|
||||
Function<Rounding, Rounding.Prepared> roundingPreparer =
|
||||
config.getValuesSource().roundingPreparer(searchContext.getQueryShardContext().getIndexReader());
|
||||
return ((AutoDateHistogramAggregatorSupplier) aggregatorSupplier).build(name, factories, numBuckets, roundingInfos,
|
||||
roundingPreparer, config, searchContext, parent, cardinality, metadata);
|
||||
return aggregatorSupplier.build(
|
||||
name,
|
||||
factories,
|
||||
numBuckets,
|
||||
roundingInfos,
|
||||
roundingPreparer,
|
||||
config,
|
||||
searchContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.elasticsearch.common.Rounding;
|
|||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
|
@ -33,7 +32,7 @@ import java.util.Map;
|
|||
import java.util.function.Function;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface AutoDateHistogramAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface AutoDateHistogramAggregatorSupplier {
|
||||
Aggregator build(
|
||||
String name,
|
||||
AggregatorFactories factories,
|
||||
|
|
|
@ -57,6 +57,8 @@ public class DateHistogramAggregationBuilder extends ValuesSourceAggregationBuil
|
|||
implements DateIntervalConsumer {
|
||||
|
||||
public static final String NAME = "date_histogram";
|
||||
public static final ValuesSourceRegistry.RegistryKey<DateHistogramAggregationSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, DateHistogramAggregationSupplier.class);
|
||||
|
||||
public static final Map<String, Rounding.DateTimeUnit> DATE_FIELD_UNITS;
|
||||
|
||||
|
@ -429,6 +431,11 @@ public class DateHistogramAggregationBuilder extends ValuesSourceAggregationBuil
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardContext,
|
||||
ValuesSourceConfig config,
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.search.aggregations.Aggregator;
|
|||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
|
@ -33,7 +32,7 @@ import java.io.IOException;
|
|||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface DateHistogramAggregationSupplier extends AggregatorSupplier {
|
||||
public interface DateHistogramAggregationSupplier {
|
||||
Aggregator build(String name,
|
||||
AggregatorFactories factories,
|
||||
Rounding rounding,
|
||||
|
|
|
@ -22,13 +22,11 @@ package org.elasticsearch.search.aggregations.bucket.histogram;
|
|||
import org.elasticsearch.common.Rounding;
|
||||
import org.elasticsearch.common.collect.List;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -41,13 +39,13 @@ import java.util.Map;
|
|||
public final class DateHistogramAggregatorFactory extends ValuesSourceAggregatorFactory {
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(DateHistogramAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
DateHistogramAggregationBuilder.REGISTRY_KEY,
|
||||
List.of(CoreValuesSourceType.DATE, CoreValuesSourceType.NUMERIC, CoreValuesSourceType.BOOLEAN),
|
||||
(DateHistogramAggregationSupplier) DateHistogramAggregator::new);
|
||||
DateHistogramAggregator::new,
|
||||
true);
|
||||
|
||||
builder.register(DateHistogramAggregationBuilder.NAME,
|
||||
CoreValuesSourceType.RANGE,
|
||||
(DateHistogramAggregationSupplier) DateRangeHistogramAggregator::new);
|
||||
builder.register(DateHistogramAggregationBuilder.REGISTRY_KEY, CoreValuesSourceType.RANGE, DateRangeHistogramAggregator::new, true);
|
||||
}
|
||||
|
||||
private final BucketOrder order;
|
||||
|
@ -90,18 +88,13 @@ public final class DateHistogramAggregatorFactory extends ValuesSourceAggregator
|
|||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> 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() + "]"
|
||||
);
|
||||
}
|
||||
DateHistogramAggregationSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(DateHistogramAggregationBuilder.REGISTRY_KEY, config);
|
||||
// TODO: Is there a reason not to get the prepared rounding in the supplier itself?
|
||||
Rounding.Prepared preparedRounding = config.getValuesSource()
|
||||
.roundingPreparer(queryShardContext.getIndexReader())
|
||||
.apply(rounding);
|
||||
return ((DateHistogramAggregationSupplier) aggregatorSupplier).build(
|
||||
return aggregatorSupplier.build(
|
||||
name,
|
||||
factories,
|
||||
rounding,
|
||||
|
|
|
@ -50,6 +50,8 @@ import java.util.Objects;
|
|||
*/
|
||||
public class HistogramAggregationBuilder extends ValuesSourceAggregationBuilder<HistogramAggregationBuilder> {
|
||||
public static final String NAME = "histogram";
|
||||
public static final ValuesSourceRegistry.RegistryKey<HistogramAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, HistogramAggregatorSupplier.class);
|
||||
|
||||
private static final ObjectParser<double[], Void> EXTENDED_BOUNDS_PARSER = new ObjectParser<>(
|
||||
Histogram.EXTENDED_BOUNDS_FIELD.getPreferredName(),
|
||||
|
@ -347,6 +349,11 @@ public class HistogramAggregationBuilder extends ValuesSourceAggregationBuilder<
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardContext,
|
||||
ValuesSourceConfig config,
|
||||
|
|
|
@ -21,13 +21,11 @@ package org.elasticsearch.search.aggregations.bucket.histogram;
|
|||
|
||||
import org.elasticsearch.common.collect.List;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -51,12 +49,13 @@ public final class HistogramAggregatorFactory extends ValuesSourceAggregatorFact
|
|||
private final DoubleBounds hardBounds;
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(HistogramAggregationBuilder.NAME, CoreValuesSourceType.RANGE,
|
||||
(HistogramAggregatorSupplier) RangeHistogramAggregator::new);
|
||||
builder.register(HistogramAggregationBuilder.REGISTRY_KEY, CoreValuesSourceType.RANGE, RangeHistogramAggregator::new, true);
|
||||
|
||||
builder.register(HistogramAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
HistogramAggregationBuilder.REGISTRY_KEY,
|
||||
List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
(HistogramAggregatorSupplier) NumericHistogramAggregator::new);
|
||||
NumericHistogramAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
public HistogramAggregatorFactory(String name,
|
||||
|
@ -91,15 +90,24 @@ public final class HistogramAggregatorFactory extends ValuesSourceAggregatorFact
|
|||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
HistogramAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof HistogramAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected HistogramAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
HistogramAggregatorSupplier histogramAggregatorSupplier = (HistogramAggregatorSupplier) aggregatorSupplier;
|
||||
return histogramAggregatorSupplier.build(name, factories, interval, offset, order, keyed, minDocCount, extendedBounds,
|
||||
hardBounds, config, searchContext, parent, cardinality, metadata);
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(HistogramAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(
|
||||
name,
|
||||
factories,
|
||||
interval,
|
||||
offset,
|
||||
order,
|
||||
keyed,
|
||||
minDocCount,
|
||||
extendedBounds,
|
||||
hardBounds,
|
||||
config,
|
||||
searchContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,14 +22,13 @@ import org.elasticsearch.search.aggregations.Aggregator;
|
|||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface HistogramAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface HistogramAggregatorSupplier {
|
||||
Aggregator build(
|
||||
String name,
|
||||
AggregatorFactories factories,
|
||||
|
|
|
@ -42,10 +42,11 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class VariableWidthHistogramAggregationBuilder
|
||||
extends ValuesSourceAggregationBuilder<VariableWidthHistogramAggregationBuilder> {
|
||||
public class VariableWidthHistogramAggregationBuilder extends ValuesSourceAggregationBuilder<VariableWidthHistogramAggregationBuilder> {
|
||||
|
||||
public static final String NAME = "variable_width_histogram";
|
||||
public static final ValuesSourceRegistry.RegistryKey<VariableWidthHistogramAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, VariableWidthHistogramAggregatorSupplier.class);
|
||||
|
||||
private static final ParseField NUM_BUCKETS_FIELD = new ParseField("buckets");
|
||||
|
||||
|
@ -213,4 +214,9 @@ public class VariableWidthHistogramAggregationBuilder
|
|||
|
||||
@Override
|
||||
public String getType() { return NAME; }
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.bucket.histogram;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -38,8 +36,11 @@ import java.util.Map;
|
|||
public class VariableWidthHistogramAggregatorFactory extends ValuesSourceAggregatorFactory {
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(VariableWidthHistogramAggregationBuilder.NAME, CoreValuesSourceType.NUMERIC,
|
||||
(VariableWidthHistogramAggregatorSupplier) VariableWidthHistogramAggregator::new);
|
||||
builder.register(
|
||||
VariableWidthHistogramAggregationBuilder.REGISTRY_KEY,
|
||||
CoreValuesSourceType.NUMERIC,
|
||||
VariableWidthHistogramAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
private final int numBuckets;
|
||||
|
@ -73,14 +74,9 @@ public class VariableWidthHistogramAggregatorFactory extends ValuesSourceAggrega
|
|||
+ "] cannot be nested inside an aggregation that collects more than a single bucket."
|
||||
);
|
||||
}
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
VariableWidthHistogramAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof VariableWidthHistogramAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected HistogramAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((VariableWidthHistogramAggregatorSupplier) aggregatorSupplier).build(name, factories, numBuckets, shardSize, initialBuffer,
|
||||
config, searchContext, parent, metadata);
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(VariableWidthHistogramAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, factories, numBuckets, shardSize, initialBuffer, config, searchContext, parent, metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.search.aggregations.bucket.histogram;
|
|||
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.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
|
@ -30,7 +29,7 @@ import java.io.IOException;
|
|||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface VariableWidthHistogramAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface VariableWidthHistogramAggregatorSupplier {
|
||||
Aggregator build(
|
||||
String name,
|
||||
AggregatorFactories factories,
|
||||
|
|
|
@ -40,6 +40,10 @@ import java.util.Map;
|
|||
|
||||
public class MissingAggregationBuilder extends ValuesSourceAggregationBuilder<MissingAggregationBuilder> {
|
||||
public static final String NAME = "missing";
|
||||
public static final ValuesSourceRegistry.RegistryKey<MissingAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
MissingAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<MissingAggregationBuilder, String> PARSER =
|
||||
ObjectParser.fromBuilder(NAME, MissingAggregationBuilder::new);
|
||||
|
@ -110,4 +114,9 @@ public class MissingAggregationBuilder extends ValuesSourceAggregationBuilder<Mi
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.bucket.missing;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -38,8 +36,7 @@ import java.util.Map;
|
|||
public class MissingAggregatorFactory extends ValuesSourceAggregatorFactory {
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(MissingAggregationBuilder.NAME, CoreValuesSourceType.ALL_CORE,
|
||||
(MissingAggregatorSupplier) MissingAggregator::new);
|
||||
builder.register(MissingAggregationBuilder.REGISTRY_KEY, CoreValuesSourceType.ALL_CORE, MissingAggregator::new, true);
|
||||
}
|
||||
|
||||
public MissingAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext,
|
||||
|
@ -60,22 +57,8 @@ public class MissingAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
final AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(config, MissingAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof MissingAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected MissingAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
|
||||
return ((MissingAggregatorSupplier) aggregatorSupplier).build(
|
||||
name,
|
||||
factories,
|
||||
config,
|
||||
searchContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(MissingAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, factories, config, searchContext, parent, cardinality, metadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.search.aggregations.bucket.missing;
|
|||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
|
@ -30,7 +29,7 @@ import java.io.IOException;
|
|||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface MissingAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface MissingAggregatorSupplier {
|
||||
|
||||
MissingAggregator build(String name,
|
||||
AggregatorFactories factories,
|
||||
|
|
|
@ -20,14 +20,12 @@
|
|||
package org.elasticsearch.search.aggregations.bucket.range;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
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.Numeric;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
|
@ -43,17 +41,21 @@ public class AbstractRangeAggregatorFactory<R extends Range> extends ValuesSourc
|
|||
private final InternalRange.Factory<?, ?> rangeFactory;
|
||||
private final R[] ranges;
|
||||
private final boolean keyed;
|
||||
private final String aggregationTypeName;
|
||||
private final ValuesSourceRegistry.RegistryKey<RangeAggregatorSupplier> registryKey;
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder,
|
||||
String aggregationName) {
|
||||
builder.register(aggregationName,
|
||||
public static void registerAggregators(
|
||||
ValuesSourceRegistry.Builder builder,
|
||||
ValuesSourceRegistry.RegistryKey<RangeAggregatorSupplier> registryKey
|
||||
) {
|
||||
builder.register(
|
||||
registryKey,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
(RangeAggregatorSupplier) RangeAggregator::new);
|
||||
RangeAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
public AbstractRangeAggregatorFactory(String name,
|
||||
String aggregationTypeName,
|
||||
ValuesSourceRegistry.RegistryKey<RangeAggregatorSupplier> registryKey,
|
||||
ValuesSourceConfig config,
|
||||
R[] ranges,
|
||||
boolean keyed,
|
||||
|
@ -66,7 +68,7 @@ public class AbstractRangeAggregatorFactory<R extends Range> extends ValuesSourc
|
|||
this.ranges = ranges;
|
||||
this.keyed = keyed;
|
||||
this.rangeFactory = rangeFactory;
|
||||
this.aggregationTypeName = aggregationTypeName;
|
||||
this.registryKey = registryKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,29 +79,27 @@ public class AbstractRangeAggregatorFactory<R extends Range> extends ValuesSourc
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
aggregationTypeName);
|
||||
if (aggregatorSupplier instanceof RangeAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected RangeAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((RangeAggregatorSupplier) aggregatorSupplier).build(
|
||||
name,
|
||||
factories,
|
||||
(Numeric) config.getValuesSource(),
|
||||
config.format(),
|
||||
rangeFactory,
|
||||
ranges,
|
||||
keyed,
|
||||
searchContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(registryKey, config)
|
||||
.build(
|
||||
name,
|
||||
factories,
|
||||
(Numeric) config.getValuesSource(),
|
||||
config.format(),
|
||||
rangeFactory,
|
||||
ranges,
|
||||
keyed,
|
||||
searchContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,10 @@
|
|||
package org.elasticsearch.search.aggregations.bucket.range;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -38,7 +36,7 @@ import java.util.Map;
|
|||
public class BinaryRangeAggregatorFactory extends ValuesSourceAggregatorFactory {
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(IpRangeAggregationBuilder.NAME, CoreValuesSourceType.IP, (IpRangeAggregatorSupplier) BinaryRangeAggregator::new);
|
||||
builder.register(IpRangeAggregationBuilder.REGISTRY_KEY, CoreValuesSourceType.IP, BinaryRangeAggregator::new, true);
|
||||
}
|
||||
|
||||
private final List<BinaryRangeAggregator.Range> ranges;
|
||||
|
@ -63,18 +61,15 @@ public class BinaryRangeAggregatorFactory extends ValuesSourceAggregatorFactory
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
IpRangeAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof IpRangeAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected IpRangeAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((IpRangeAggregatorSupplier) aggregatorSupplier).build(name, factories, config.getValuesSource(), config.format(),
|
||||
ranges, keyed, searchContext, parent, cardinality, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(IpRangeAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, factories, config.getValuesSource(), config.format(), ranges, keyed, searchContext, parent, cardinality, metadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,10 @@ import java.util.Map;
|
|||
|
||||
public class DateRangeAggregationBuilder extends AbstractRangeBuilder<DateRangeAggregationBuilder, RangeAggregator.Range> {
|
||||
public static final String NAME = "date_range";
|
||||
public static final ValuesSourceRegistry.RegistryKey<RangeAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
RangeAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<DateRangeAggregationBuilder, String> PARSER =
|
||||
ObjectParser.fromBuilder(NAME, DateRangeAggregationBuilder::new);
|
||||
|
@ -53,7 +57,7 @@ public class DateRangeAggregationBuilder extends AbstractRangeBuilder<DateRangeA
|
|||
}
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
AbstractRangeAggregatorFactory.registerAggregators(builder, NAME);
|
||||
AbstractRangeAggregatorFactory.registerAggregators(builder, REGISTRY_KEY);
|
||||
}
|
||||
|
||||
public DateRangeAggregationBuilder(String name) {
|
||||
|
@ -83,6 +87,11 @@ public class DateRangeAggregationBuilder extends AbstractRangeBuilder<DateRangeA
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceType defaultValueSourceType() {
|
||||
return CoreValuesSourceType.DATE;
|
||||
|
|
|
@ -29,17 +29,29 @@ import java.util.Map;
|
|||
|
||||
public class DateRangeAggregatorFactory extends AbstractRangeAggregatorFactory<RangeAggregator.Range> {
|
||||
|
||||
public DateRangeAggregatorFactory(String name,
|
||||
ValuesSourceConfig config,
|
||||
RangeAggregator.Range[] ranges,
|
||||
boolean keyed,
|
||||
InternalRange.Factory<?, ?> rangeFactory,
|
||||
QueryShardContext queryShardContext,
|
||||
AggregatorFactory parent,
|
||||
AggregatorFactories.Builder subFactoriesBuilder,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
super(name, DateRangeAggregationBuilder.NAME, config, ranges, keyed, rangeFactory, queryShardContext, parent, subFactoriesBuilder,
|
||||
metadata);
|
||||
public DateRangeAggregatorFactory(
|
||||
String name,
|
||||
ValuesSourceConfig config,
|
||||
RangeAggregator.Range[] ranges,
|
||||
boolean keyed,
|
||||
InternalRange.Factory<?, ?> rangeFactory,
|
||||
QueryShardContext queryShardContext,
|
||||
AggregatorFactory parent,
|
||||
AggregatorFactories.Builder subFactoriesBuilder,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
super(
|
||||
name,
|
||||
DateRangeAggregationBuilder.REGISTRY_KEY,
|
||||
config,
|
||||
ranges,
|
||||
keyed,
|
||||
rangeFactory,
|
||||
queryShardContext,
|
||||
parent,
|
||||
subFactoriesBuilder,
|
||||
metadata
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ import static org.elasticsearch.search.aggregations.bucket.range.RangeAggregator
|
|||
|
||||
public class GeoDistanceAggregationBuilder extends ValuesSourceAggregationBuilder<GeoDistanceAggregationBuilder> {
|
||||
public static final String NAME = "geo_distance";
|
||||
public static final ValuesSourceRegistry.RegistryKey<GeoDistanceAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, GeoDistanceAggregatorSupplier.class);
|
||||
static final ParseField ORIGIN_FIELD = new ParseField("origin", "center", "point", "por");
|
||||
static final ParseField UNIT_FIELD = new ParseField("unit");
|
||||
static final ParseField DISTANCE_TYPE_FIELD = new ParseField("distance_type");
|
||||
|
@ -388,6 +390,11 @@ public class GeoDistanceAggregationBuilder extends ValuesSourceAggregationBuilde
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
|
||||
public GeoDistanceAggregationBuilder unit(DistanceUnit unit) {
|
||||
if (unit == null) {
|
||||
throw new IllegalArgumentException("[unit] must not be null: [" + name + "]");
|
||||
|
|
|
@ -25,14 +25,13 @@ import org.elasticsearch.search.DocValueFormat;
|
|||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
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 GeoDistanceAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface GeoDistanceAggregatorSupplier {
|
||||
Aggregator build(
|
||||
String name,
|
||||
AggregatorFactories factories,
|
||||
|
|
|
@ -29,13 +29,11 @@ import org.elasticsearch.index.fielddata.MultiGeoPointValues;
|
|||
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
|
||||
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.bucket.range.GeoDistanceAggregationBuilder.Range;
|
||||
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;
|
||||
|
@ -49,13 +47,40 @@ import java.util.Map;
|
|||
public class GeoDistanceRangeAggregatorFactory extends ValuesSourceAggregatorFactory {
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(GeoDistanceAggregationBuilder.NAME, CoreValuesSourceType.GEOPOINT,
|
||||
(GeoDistanceAggregatorSupplier) (name, factories, distanceType, origin, units, valuesSource, format, rangeFactory, ranges, keyed,
|
||||
context, parent, cardinality, metadata) -> {
|
||||
DistanceSource distanceSource = new DistanceSource((ValuesSource.GeoPoint) valuesSource, distanceType, origin, units);
|
||||
return new RangeAggregator(name, factories, distanceSource, format, rangeFactory, ranges, keyed, context, parent,
|
||||
cardinality, metadata);
|
||||
});
|
||||
builder.register(
|
||||
GeoDistanceAggregationBuilder.REGISTRY_KEY,
|
||||
CoreValuesSourceType.GEOPOINT,
|
||||
(
|
||||
name,
|
||||
factories,
|
||||
distanceType,
|
||||
origin,
|
||||
units,
|
||||
valuesSource,
|
||||
format,
|
||||
rangeFactory,
|
||||
ranges,
|
||||
keyed,
|
||||
context,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata) -> {
|
||||
DistanceSource distanceSource = new DistanceSource((ValuesSource.GeoPoint) valuesSource, distanceType, origin, units);
|
||||
return new RangeAggregator(
|
||||
name,
|
||||
factories,
|
||||
distanceSource,
|
||||
format,
|
||||
rangeFactory,
|
||||
ranges,
|
||||
keyed,
|
||||
context,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
private final InternalRange.Factory<InternalGeoDistance.Bucket, InternalGeoDistance> rangeFactory = InternalGeoDistance.FACTORY;
|
||||
|
@ -87,18 +112,30 @@ public class GeoDistanceRangeAggregatorFactory extends ValuesSourceAggregatorFac
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(config, GeoDistanceAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof GeoDistanceAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected "
|
||||
+ GeoDistanceAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((GeoDistanceAggregatorSupplier) aggregatorSupplier).build(name, factories, distanceType, origin,
|
||||
unit, config.getValuesSource(), config.format(), rangeFactory, ranges, keyed, searchContext, parent, cardinality, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(GeoDistanceAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(
|
||||
name,
|
||||
factories,
|
||||
distanceType,
|
||||
origin,
|
||||
unit,
|
||||
config.getValuesSource(),
|
||||
config.format(),
|
||||
rangeFactory,
|
||||
ranges,
|
||||
keyed,
|
||||
searchContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
}
|
||||
|
||||
private static class DistanceSource extends ValuesSource.Numeric {
|
||||
|
|
|
@ -53,9 +53,12 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
|
||||
|
||||
public final class IpRangeAggregationBuilder
|
||||
extends ValuesSourceAggregationBuilder<IpRangeAggregationBuilder> {
|
||||
public final class IpRangeAggregationBuilder extends ValuesSourceAggregationBuilder<IpRangeAggregationBuilder> {
|
||||
public static final String NAME = "ip_range";
|
||||
public static final ValuesSourceRegistry.RegistryKey<IpRangeAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
IpRangeAggregatorSupplier.class
|
||||
);
|
||||
private static final ParseField MASK_FIELD = new ParseField("mask");
|
||||
|
||||
public static final ObjectParser<IpRangeAggregationBuilder, String> PARSER =
|
||||
|
@ -238,6 +241,11 @@ public final class IpRangeAggregationBuilder
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
|
||||
public IpRangeAggregationBuilder keyed(boolean keyed) {
|
||||
this.keyed = keyed;
|
||||
return this;
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.elasticsearch.search.DocValueFormat;
|
|||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSource;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
|
@ -31,7 +30,7 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IpRangeAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface IpRangeAggregatorSupplier {
|
||||
|
||||
Aggregator build(String name,
|
||||
AggregatorFactories factories,
|
||||
|
|
|
@ -36,6 +36,10 @@ import java.util.Map;
|
|||
|
||||
public class RangeAggregationBuilder extends AbstractRangeBuilder<RangeAggregationBuilder, Range> {
|
||||
public static final String NAME = "range";
|
||||
public static final ValuesSourceRegistry.RegistryKey<RangeAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
RangeAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<RangeAggregationBuilder, String> PARSER =
|
||||
ObjectParser.fromBuilder(NAME, RangeAggregationBuilder::new);
|
||||
|
@ -51,7 +55,7 @@ public class RangeAggregationBuilder extends AbstractRangeBuilder<RangeAggregati
|
|||
}
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
AbstractRangeAggregatorFactory.registerAggregators(builder, NAME);
|
||||
AbstractRangeAggregatorFactory.registerAggregators(builder, REGISTRY_KEY);
|
||||
}
|
||||
|
||||
public RangeAggregationBuilder(String name) {
|
||||
|
@ -171,4 +175,9 @@ public class RangeAggregationBuilder extends AbstractRangeBuilder<RangeAggregati
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,17 +31,28 @@ import java.util.Map;
|
|||
|
||||
public class RangeAggregatorFactory extends AbstractRangeAggregatorFactory<RangeAggregator.Range> {
|
||||
|
||||
public RangeAggregatorFactory(String name,
|
||||
ValuesSourceConfig config,
|
||||
Range[] ranges,
|
||||
boolean keyed,
|
||||
Factory<?, ?> rangeFactory,
|
||||
QueryShardContext queryShardContext,
|
||||
AggregatorFactory parent,
|
||||
AggregatorFactories.Builder subFactoriesBuilder,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
super(name, RangeAggregationBuilder.NAME, config, ranges, keyed, rangeFactory, queryShardContext, parent, subFactoriesBuilder,
|
||||
metadata);
|
||||
public RangeAggregatorFactory(
|
||||
String name,
|
||||
ValuesSourceConfig config,
|
||||
Range[] ranges,
|
||||
boolean keyed,
|
||||
Factory<?, ?> rangeFactory,
|
||||
QueryShardContext queryShardContext,
|
||||
AggregatorFactory parent,
|
||||
AggregatorFactories.Builder subFactoriesBuilder,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
super(
|
||||
name,
|
||||
RangeAggregationBuilder.REGISTRY_KEY,
|
||||
config,
|
||||
ranges,
|
||||
keyed,
|
||||
rangeFactory,
|
||||
queryShardContext,
|
||||
parent,
|
||||
subFactoriesBuilder,
|
||||
metadata
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,14 +22,13 @@ import org.elasticsearch.search.DocValueFormat;
|
|||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
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 RangeAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface RangeAggregatorSupplier {
|
||||
Aggregator build(String name,
|
||||
AggregatorFactories factories,
|
||||
ValuesSource.Numeric valuesSource,
|
||||
|
|
|
@ -40,6 +40,8 @@ import java.util.Objects;
|
|||
|
||||
public class DiversifiedAggregationBuilder extends ValuesSourceAggregationBuilder<DiversifiedAggregationBuilder> {
|
||||
public static final String NAME = "diversified_sampler";
|
||||
public static final ValuesSourceRegistry.RegistryKey<DiversifiedAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, DiversifiedAggregatorSupplier.class);
|
||||
|
||||
public static final int MAX_DOCS_PER_VALUE_DEFAULT = 1;
|
||||
|
||||
|
@ -195,4 +197,9 @@ public class DiversifiedAggregationBuilder extends ValuesSourceAggregationBuilde
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.search.aggregations.bucket.sampler;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
|
@ -28,7 +27,6 @@ import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
|||
import org.elasticsearch.search.aggregations.InternalAggregation;
|
||||
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.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -41,22 +39,46 @@ import java.util.Map;
|
|||
public class DiversifiedAggregatorFactory extends ValuesSourceAggregatorFactory {
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(DiversifiedAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
DiversifiedAggregationBuilder.REGISTRY_KEY,
|
||||
org.elasticsearch.common.collect.List.of(
|
||||
CoreValuesSourceType.NUMERIC,
|
||||
CoreValuesSourceType.DATE,
|
||||
CoreValuesSourceType.BOOLEAN),
|
||||
(DiversifiedAggregatorSupplier) (String name, int shardSize, AggregatorFactories factories, SearchContext context,
|
||||
Aggregator parent, Map<String, Object> metadata, ValuesSourceConfig valuesSourceConfig,
|
||||
int maxDocsPerValue, String executionHint) ->
|
||||
new DiversifiedNumericSamplerAggregator(name, shardSize, factories, context, parent, metadata, valuesSourceConfig,
|
||||
maxDocsPerValue)
|
||||
);
|
||||
(
|
||||
String name,
|
||||
int shardSize,
|
||||
AggregatorFactories factories,
|
||||
SearchContext context,
|
||||
Aggregator parent,
|
||||
Map<String, Object> metadata,
|
||||
ValuesSourceConfig valuesSourceConfig,
|
||||
int maxDocsPerValue,
|
||||
String executionHint) -> new DiversifiedNumericSamplerAggregator(
|
||||
name,
|
||||
shardSize,
|
||||
factories,
|
||||
context,
|
||||
parent,
|
||||
metadata,
|
||||
valuesSourceConfig,
|
||||
maxDocsPerValue
|
||||
),
|
||||
true);
|
||||
|
||||
builder.register(DiversifiedAggregationBuilder.NAME, CoreValuesSourceType.BYTES,
|
||||
(DiversifiedAggregatorSupplier) (String name, int shardSize, AggregatorFactories factories, SearchContext context,
|
||||
Aggregator parent, Map<String, Object> metadata, ValuesSourceConfig valuesSourceConfig,
|
||||
int maxDocsPerValue, String executionHint) -> {
|
||||
builder.register(
|
||||
DiversifiedAggregationBuilder.REGISTRY_KEY,
|
||||
CoreValuesSourceType.BYTES,
|
||||
(
|
||||
String name,
|
||||
int shardSize,
|
||||
AggregatorFactories factories,
|
||||
SearchContext context,
|
||||
Aggregator parent,
|
||||
Map<String, Object> metadata,
|
||||
ValuesSourceConfig valuesSourceConfig,
|
||||
int maxDocsPerValue,
|
||||
String executionHint) -> {
|
||||
ExecutionMode execution = null;
|
||||
if (executionHint != null) {
|
||||
execution = ExecutionMode.fromString(executionHint);
|
||||
|
@ -70,8 +92,8 @@ public class DiversifiedAggregatorFactory extends ValuesSourceAggregatorFactory
|
|||
execution = ExecutionMode.MAP;
|
||||
}
|
||||
return execution.create(name, factories, shardSize, maxDocsPerValue, valuesSourceConfig, context, parent, metadata);
|
||||
});
|
||||
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
private final int shardSize;
|
||||
|
@ -93,13 +115,9 @@ public class DiversifiedAggregatorFactory extends ValuesSourceAggregatorFactory
|
|||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
|
||||
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,
|
||||
config, maxDocsPerValue, executionHint);
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(DiversifiedAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, shardSize, factories, searchContext, parent, metadata, config, maxDocsPerValue, executionHint);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,14 +21,13 @@ 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.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface DiversifiedAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface DiversifiedAggregatorSupplier {
|
||||
Aggregator build(
|
||||
String name,
|
||||
int shardSize,
|
||||
|
|
|
@ -41,6 +41,8 @@ import java.util.Objects;
|
|||
|
||||
public class RareTermsAggregationBuilder extends ValuesSourceAggregationBuilder<RareTermsAggregationBuilder> {
|
||||
public static final String NAME = "rare_terms";
|
||||
public static final ValuesSourceRegistry.RegistryKey<RareTermsAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, RareTermsAggregatorSupplier.class);
|
||||
|
||||
private static final ParseField MAX_DOC_COUNT_FIELD_NAME = new ParseField("max_doc_count");
|
||||
private static final ParseField PRECISION = new ParseField("precision");
|
||||
|
@ -211,4 +213,8 @@ public class RareTermsAggregationBuilder extends ValuesSourceAggregationBuilder<
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,14 +23,12 @@ import org.elasticsearch.common.ParseField;
|
|||
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.InternalAggregation;
|
||||
import org.elasticsearch.search.aggregations.NonCollectingAggregator;
|
||||
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;
|
||||
|
@ -48,13 +46,13 @@ public class RareTermsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
private final double precision;
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(RareTermsAggregationBuilder.NAME,
|
||||
builder.register(RareTermsAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.BYTES, CoreValuesSourceType.IP),
|
||||
RareTermsAggregatorFactory.bytesSupplier());
|
||||
RareTermsAggregatorFactory.bytesSupplier(), true);
|
||||
|
||||
builder.register(RareTermsAggregationBuilder.NAME,
|
||||
builder.register(RareTermsAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN, CoreValuesSourceType.NUMERIC),
|
||||
RareTermsAggregatorFactory.numericSupplier());
|
||||
RareTermsAggregatorFactory.numericSupplier(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,19 +174,27 @@ public class RareTermsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
RareTermsAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof RareTermsAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected RareTermsAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
|
||||
return ((RareTermsAggregatorSupplier) aggregatorSupplier).build(name, factories, config.getValuesSource(), config.format(),
|
||||
maxDocCount, precision, includeExclude, searchContext, parent, cardinality, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(RareTermsAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(
|
||||
name,
|
||||
factories,
|
||||
config.getValuesSource(),
|
||||
config.format(),
|
||||
maxDocCount,
|
||||
precision,
|
||||
includeExclude,
|
||||
searchContext,
|
||||
parent,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
}
|
||||
|
||||
public enum ExecutionMode {
|
||||
|
|
|
@ -22,14 +22,13 @@ import org.elasticsearch.search.DocValueFormat;
|
|||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
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;
|
||||
|
||||
interface RareTermsAggregatorSupplier extends AggregatorSupplier {
|
||||
interface RareTermsAggregatorSupplier {
|
||||
Aggregator build(String name,
|
||||
AggregatorFactories factories,
|
||||
ValuesSource valuesSource,
|
||||
|
|
|
@ -49,6 +49,8 @@ import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQuery
|
|||
|
||||
public class SignificantTermsAggregationBuilder extends ValuesSourceAggregationBuilder<SignificantTermsAggregationBuilder> {
|
||||
public static final String NAME = "significant_terms";
|
||||
public static final ValuesSourceRegistry.RegistryKey<SignificantTermsAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, SignificantTermsAggregatorSupplier.class);
|
||||
|
||||
static final ParseField BACKGROUND_FILTER = new ParseField("background_filter");
|
||||
static final ParseField HEURISTIC = new ParseField("significance_heuristic");
|
||||
|
@ -337,4 +339,9 @@ public class SignificantTermsAggregationBuilder extends ValuesSourceAggregationB
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.common.logging.DeprecationLogger;
|
|||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
|
@ -36,7 +35,6 @@ import org.elasticsearch.search.aggregations.NonCollectingAggregator;
|
|||
import org.elasticsearch.search.aggregations.bucket.BucketUtils;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregator.BucketCountThresholds;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.heuristic.SignificanceHeuristic;
|
||||
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;
|
||||
|
@ -53,13 +51,13 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac
|
|||
LogManager.getLogger(SignificantTermsAggregatorFactory.class));
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(SignificantTermsAggregationBuilder.NAME,
|
||||
builder.register(SignificantTermsAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.BYTES, CoreValuesSourceType.IP),
|
||||
SignificantTermsAggregatorFactory.bytesSupplier());
|
||||
SignificantTermsAggregatorFactory.bytesSupplier(), true);
|
||||
|
||||
builder.register(SignificantTermsAggregationBuilder.NAME,
|
||||
builder.register(SignificantTermsAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN, CoreValuesSourceType.NUMERIC),
|
||||
SignificantTermsAggregatorFactory.numericSupplier());
|
||||
SignificantTermsAggregatorFactory.numericSupplier(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,17 +197,14 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
SignificantTermsAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof SignificantTermsAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected SignificantTermsAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
SignificantTermsAggregatorSupplier sigTermsAggregatorSupplier = (SignificantTermsAggregatorSupplier) aggregatorSupplier;
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
SignificantTermsAggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(SignificantTermsAggregationBuilder.REGISTRY_KEY, config);
|
||||
|
||||
BucketCountThresholds bucketCountThresholds = new BucketCountThresholds(this.bucketCountThresholds);
|
||||
if (bucketCountThresholds.getShardSize() == SignificantTermsAggregationBuilder.DEFAULT_BUCKET_COUNT_THRESHOLDS.getShardSize()) {
|
||||
|
@ -235,9 +230,21 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac
|
|||
backgroundFilter
|
||||
);
|
||||
|
||||
return sigTermsAggregatorSupplier.build(name, factories, config.getValuesSource(), config.format(),
|
||||
bucketCountThresholds, includeExclude, executionHint, searchContext, parent,
|
||||
significanceHeuristic, lookup, cardinality, metadata);
|
||||
return aggregatorSupplier.build(
|
||||
name,
|
||||
factories,
|
||||
config.getValuesSource(),
|
||||
config.format(),
|
||||
bucketCountThresholds,
|
||||
includeExclude,
|
||||
executionHint,
|
||||
searchContext,
|
||||
parent,
|
||||
significanceHeuristic,
|
||||
lookup,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
}
|
||||
|
||||
public enum ExecutionMode {
|
||||
|
|
|
@ -23,14 +23,13 @@ import org.elasticsearch.search.aggregations.Aggregator;
|
|||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.heuristic.SignificanceHeuristic;
|
||||
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;
|
||||
|
||||
interface SignificantTermsAggregatorSupplier extends AggregatorSupplier {
|
||||
interface SignificantTermsAggregatorSupplier {
|
||||
Aggregator build(String name,
|
||||
AggregatorFactories factories,
|
||||
ValuesSource valuesSource,
|
||||
|
|
|
@ -49,6 +49,10 @@ import java.util.Objects;
|
|||
|
||||
public class TermsAggregationBuilder extends ValuesSourceAggregationBuilder<TermsAggregationBuilder> {
|
||||
public static final String NAME = "terms";
|
||||
public static final ValuesSourceRegistry.RegistryKey<TermsAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
TermsAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ParseField EXECUTION_HINT_FIELD_NAME = new ParseField("execution_hint");
|
||||
public static final ParseField SHARD_SIZE_FIELD_NAME = new ParseField("shard_size");
|
||||
|
@ -398,4 +402,9 @@ public class TermsAggregationBuilder extends ValuesSourceAggregationBuilder<Term
|
|||
protected AggregationBuilder doRewrite(QueryRewriteContext queryShardContext) throws IOException {
|
||||
return super.doRewrite(queryShardContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ import org.elasticsearch.search.aggregations.Aggregator;
|
|||
import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.InternalAggregation;
|
||||
import org.elasticsearch.search.aggregations.InternalOrder;
|
||||
import org.elasticsearch.search.aggregations.InternalOrder.CompoundOrder;
|
||||
|
@ -37,7 +37,6 @@ import org.elasticsearch.search.aggregations.NonCollectingAggregator;
|
|||
import org.elasticsearch.search.aggregations.bucket.BucketUtils;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator.ResultStrategy;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregator.BucketCountThresholds;
|
||||
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;
|
||||
|
@ -54,13 +53,13 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
static Boolean REMAP_GLOBAL_ORDS, COLLECT_SEGMENT_ORDS;
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(TermsAggregationBuilder.NAME,
|
||||
builder.register(TermsAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.BYTES, CoreValuesSourceType.IP),
|
||||
TermsAggregatorFactory.bytesSupplier());
|
||||
TermsAggregatorFactory.bytesSupplier(), true);
|
||||
|
||||
builder.register(TermsAggregationBuilder.NAME,
|
||||
builder.register(TermsAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN, CoreValuesSourceType.NUMERIC),
|
||||
TermsAggregatorFactory.numericSupplier());
|
||||
TermsAggregatorFactory.numericSupplier(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,18 +223,14 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
TermsAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof TermsAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected TermsAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
|
||||
TermsAggregatorSupplier termsAggregatorSupplier = (TermsAggregatorSupplier) aggregatorSupplier;
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
TermsAggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(TermsAggregationBuilder.REGISTRY_KEY, config);
|
||||
BucketCountThresholds bucketCountThresholds = new BucketCountThresholds(this.bucketCountThresholds);
|
||||
if (InternalOrder.isKeyOrder(order) == false
|
||||
&& bucketCountThresholds.getShardSize() == TermsAggregationBuilder.DEFAULT_BUCKET_COUNT_THRESHOLDS.getShardSize()) {
|
||||
|
@ -246,9 +241,22 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
bucketCountThresholds.ensureValidity();
|
||||
|
||||
return termsAggregatorSupplier.build(name, factories, config.getValuesSource(), order, config.format(),
|
||||
bucketCountThresholds, includeExclude, executionHint, searchContext, parent, collectMode,
|
||||
showTermDocCountError, cardinality, metadata);
|
||||
return aggregatorSupplier.build(
|
||||
name,
|
||||
factories,
|
||||
config.getValuesSource(),
|
||||
order,
|
||||
config.format(),
|
||||
bucketCountThresholds,
|
||||
includeExclude,
|
||||
executionHint,
|
||||
searchContext,
|
||||
parent,
|
||||
collectMode,
|
||||
showTermDocCountError,
|
||||
cardinality,
|
||||
metadata
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,14 +23,13 @@ import org.elasticsearch.search.aggregations.Aggregator;
|
|||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||
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;
|
||||
|
||||
interface TermsAggregatorSupplier extends AggregatorSupplier {
|
||||
interface TermsAggregatorSupplier {
|
||||
Aggregator build(String name,
|
||||
AggregatorFactories factories,
|
||||
ValuesSource valuesSource,
|
||||
|
|
|
@ -39,6 +39,10 @@ import java.util.Map;
|
|||
|
||||
public class AvgAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource.Numeric, AvgAggregationBuilder> {
|
||||
public static final String NAME = "avg";
|
||||
public static final ValuesSourceRegistry.RegistryKey<MetricAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
MetricAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<AvgAggregationBuilder, String> PARSER = ObjectParser.fromBuilder(NAME, AvgAggregationBuilder::new);
|
||||
static {
|
||||
|
@ -95,4 +99,9 @@ public class AvgAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOn
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -44,10 +42,11 @@ class AvgAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(AvgAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
AvgAggregationBuilder.REGISTRY_KEY,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
(MetricAggregatorSupplier) AvgAggregator::new
|
||||
);
|
||||
AvgAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,17 +57,14 @@ class AvgAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
AvgAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(AvgAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config, searchContext, parent, metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ public final class CardinalityAggregationBuilder
|
|||
extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource, CardinalityAggregationBuilder> {
|
||||
|
||||
public static final String NAME = "cardinality";
|
||||
public static final ValuesSourceRegistry.RegistryKey<CardinalityAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, CardinalityAggregatorSupplier.class);
|
||||
|
||||
private static final ParseField REHASH = new ParseField("rehash").withAllDeprecated("no replacement - values will always be rehashed");
|
||||
public static final ParseField PRECISION_THRESHOLD_FIELD = new ParseField("precision_threshold");
|
||||
|
@ -162,4 +164,9 @@ public final class CardinalityAggregationBuilder
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -50,8 +48,7 @@ class CardinalityAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(CardinalityAggregationBuilder.NAME, CoreValuesSourceType.ALL_CORE,
|
||||
(CardinalityAggregatorSupplier) CardinalityAggregator::new);
|
||||
builder.register(CardinalityAggregationBuilder.REGISTRY_KEY, CoreValuesSourceType.ALL_CORE, CardinalityAggregator::new, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,18 +59,15 @@ class CardinalityAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
CardinalityAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof CardinalityAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected CardinalityAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
CardinalityAggregatorSupplier cardinalityAggregatorSupplier = (CardinalityAggregatorSupplier) aggregatorSupplier;
|
||||
return cardinalityAggregatorSupplier.build(name, config, precision(), searchContext, parent, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(CardinalityAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config, precision(), searchContext, parent, metadata);
|
||||
}
|
||||
|
||||
private int precision() {
|
||||
|
|
|
@ -20,14 +20,13 @@
|
|||
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.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface CardinalityAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface CardinalityAggregatorSupplier {
|
||||
Aggregator build(String name,
|
||||
ValuesSourceConfig valuesSourceConfig,
|
||||
int precision,
|
||||
|
|
|
@ -41,6 +41,8 @@ import java.util.Objects;
|
|||
public class ExtendedStatsAggregationBuilder
|
||||
extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource.Numeric, ExtendedStatsAggregationBuilder> {
|
||||
public static final String NAME = "extended_stats";
|
||||
public static final ValuesSourceRegistry.RegistryKey<ExtendedStatsAggregatorProvider> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, ExtendedStatsAggregatorProvider.class);
|
||||
|
||||
public static final ObjectParser<ExtendedStatsAggregationBuilder, String> PARSER =
|
||||
ObjectParser.fromBuilder(NAME, ExtendedStatsAggregationBuilder::new);
|
||||
|
@ -131,4 +133,9 @@ public class ExtendedStatsAggregationBuilder
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -52,9 +50,11 @@ class ExtendedStatsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(ExtendedStatsAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
ExtendedStatsAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
(ExtendedStatsAggregatorProvider) ExtendedStatsAggregator::new);
|
||||
ExtendedStatsAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,17 +65,14 @@ class ExtendedStatsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
ExtendedStatsAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof ExtendedStatsAggregatorProvider == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected ExtendedStatsAggregatorProvider, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return new ExtendedStatsAggregator(name, config, searchContext, parent, sigma, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(ExtendedStatsAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config, searchContext, parent, sigma, metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,13 @@
|
|||
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.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ExtendedStatsAggregatorProvider extends AggregatorSupplier {
|
||||
public interface ExtendedStatsAggregatorProvider {
|
||||
|
||||
Aggregator build(String name,
|
||||
ValuesSourceConfig valuesSourceConfig,
|
||||
|
|
|
@ -39,6 +39,8 @@ import java.util.Objects;
|
|||
|
||||
public class GeoBoundsAggregationBuilder extends ValuesSourceAggregationBuilder<GeoBoundsAggregationBuilder> {
|
||||
public static final String NAME = "geo_bounds";
|
||||
public static final ValuesSourceRegistry.RegistryKey<GeoBoundsAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, GeoBoundsAggregatorSupplier.class);
|
||||
|
||||
public static final ObjectParser<GeoBoundsAggregationBuilder, String> PARSER =
|
||||
ObjectParser.fromBuilder(NAME, GeoBoundsAggregationBuilder::new);
|
||||
|
@ -138,4 +140,9 @@ public class GeoBoundsAggregationBuilder extends ValuesSourceAggregationBuilder<
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -58,23 +56,18 @@ class GeoBoundsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(config, GeoBoundsAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof GeoBoundsAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected "
|
||||
+ GeoBoundsAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
|
||||
return ((GeoBoundsAggregatorSupplier) aggregatorSupplier).build(name, searchContext, parent, config, wrapLongitude, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(GeoBoundsAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, searchContext, parent, config, wrapLongitude, metadata);
|
||||
}
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(GeoBoundsAggregationBuilder.NAME, CoreValuesSourceType.GEOPOINT,
|
||||
(GeoBoundsAggregatorSupplier) GeoBoundsAggregator::new);
|
||||
builder.register(GeoBoundsAggregationBuilder.REGISTRY_KEY, CoreValuesSourceType.GEOPOINT, GeoBoundsAggregator::new, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
|
@ -28,7 +27,7 @@ import java.io.IOException;
|
|||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface GeoBoundsAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface GeoBoundsAggregatorSupplier {
|
||||
|
||||
MetricsAggregator build(
|
||||
String name,
|
||||
|
|
|
@ -40,6 +40,10 @@ import java.util.Map;
|
|||
public class GeoCentroidAggregationBuilder
|
||||
extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource.GeoPoint, GeoCentroidAggregationBuilder> {
|
||||
public static final String NAME = "geo_centroid";
|
||||
public static final ValuesSourceRegistry.RegistryKey<MetricAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
MetricAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<GeoCentroidAggregationBuilder, String> PARSER =
|
||||
ObjectParser.fromBuilder(NAME, GeoCentroidAggregationBuilder::new);
|
||||
|
@ -99,4 +103,9 @@ public class GeoCentroidAggregationBuilder
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -54,22 +52,18 @@ class GeoCentroidAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
GeoCentroidAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected "
|
||||
+ MetricAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(GeoCentroidAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config, searchContext, parent, metadata);
|
||||
}
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(GeoCentroidAggregationBuilder.NAME, CoreValuesSourceType.GEOPOINT,
|
||||
(MetricAggregatorSupplier) GeoCentroidAggregator::new);
|
||||
builder.register(GeoCentroidAggregationBuilder.REGISTRY_KEY, CoreValuesSourceType.GEOPOINT, GeoCentroidAggregator::new, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.elasticsearch.search.aggregations.Aggregator;
|
|||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregator;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSource;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
|
@ -32,7 +31,7 @@ import java.io.IOException;
|
|||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface GeoGridAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface GeoGridAggregatorSupplier {
|
||||
GeoGridAggregator build(
|
||||
String name,
|
||||
AggregatorFactories factories,
|
||||
|
|
|
@ -39,6 +39,10 @@ import java.util.Map;
|
|||
|
||||
public class MaxAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource.Numeric, MaxAggregationBuilder> {
|
||||
public static final String NAME = "max";
|
||||
public static final ValuesSourceRegistry.RegistryKey<MetricAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
MetricAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<MaxAggregationBuilder, String> PARSER = ObjectParser.fromBuilder(NAME, MaxAggregationBuilder::new);
|
||||
static {
|
||||
|
@ -97,4 +101,9 @@ public class MaxAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOn
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -38,9 +36,11 @@ import java.util.Map;
|
|||
class MaxAggregatorFactory extends ValuesSourceAggregatorFactory {
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(MaxAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
MaxAggregationBuilder.REGISTRY_KEY,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
(MetricAggregatorSupplier) MaxAggregator::new);
|
||||
MaxAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
MaxAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext,
|
||||
|
@ -57,17 +57,14 @@ class MaxAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
MaxAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(MaxAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config, searchContext, parent, metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ import java.util.Objects;
|
|||
public class MedianAbsoluteDeviationAggregationBuilder extends LeafOnly<ValuesSource.Numeric, MedianAbsoluteDeviationAggregationBuilder> {
|
||||
|
||||
public static final String NAME = "median_absolute_deviation";
|
||||
public static final ValuesSourceRegistry.RegistryKey<MedianAbsoluteDeviationAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, MedianAbsoluteDeviationAggregatorSupplier.class);
|
||||
|
||||
private static final ParseField COMPRESSION_FIELD = new ParseField("compression");
|
||||
|
||||
|
@ -144,4 +146,9 @@ public class MedianAbsoluteDeviationAggregationBuilder extends LeafOnly<ValuesSo
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -52,8 +50,11 @@ public class MedianAbsoluteDeviationAggregatorFactory extends ValuesSourceAggreg
|
|||
}
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(MedianAbsoluteDeviationAggregationBuilder.NAME,
|
||||
CoreValuesSourceType.NUMERIC, (MedianAbsoluteDeviationAggregatorSupplier) MedianAbsoluteDeviationAggregator::new);
|
||||
builder.register(
|
||||
MedianAbsoluteDeviationAggregationBuilder.REGISTRY_KEY,
|
||||
CoreValuesSourceType.NUMERIC,
|
||||
MedianAbsoluteDeviationAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,18 +74,14 @@ public class MedianAbsoluteDeviationAggregatorFactory extends ValuesSourceAggreg
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
MedianAbsoluteDeviationAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof MedianAbsoluteDeviationAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected MedianAbsoluteDeviationAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((MedianAbsoluteDeviationAggregatorSupplier) aggregatorSupplier).build(name, config.getValuesSource(), config.format(),
|
||||
searchContext, parent, metadata, compression);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(MedianAbsoluteDeviationAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config.getValuesSource(), config.format(), searchContext, parent, metadata, compression);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,13 @@ 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.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface MedianAbsoluteDeviationAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface MedianAbsoluteDeviationAggregatorSupplier {
|
||||
Aggregator build(String name,
|
||||
ValuesSource valuesSource,
|
||||
DocValueFormat format,
|
||||
|
|
|
@ -19,14 +19,13 @@
|
|||
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.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface MetricAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface MetricAggregatorSupplier {
|
||||
Aggregator build(String name,
|
||||
ValuesSourceConfig valuesSourceConfig,
|
||||
SearchContext context,
|
||||
|
|
|
@ -39,6 +39,10 @@ import java.util.Map;
|
|||
|
||||
public class MinAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource.Numeric, MinAggregationBuilder> {
|
||||
public static final String NAME = "min";
|
||||
public static final ValuesSourceRegistry.RegistryKey<MetricAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
MetricAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<MinAggregationBuilder, String> PARSER = ObjectParser.fromBuilder(NAME, MinAggregationBuilder::new);
|
||||
static {
|
||||
|
@ -97,4 +101,9 @@ public class MinAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOn
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -38,9 +36,11 @@ import java.util.Map;
|
|||
class MinAggregatorFactory extends ValuesSourceAggregatorFactory {
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(MinAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
MinAggregationBuilder.REGISTRY_KEY,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
(MetricAggregatorSupplier) MinAggregator::new);
|
||||
MinAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
MinAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext,
|
||||
|
@ -57,17 +57,14 @@ class MinAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound bucketCardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
MinAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound bucketCardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(MinAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config, searchContext, parent, metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ import java.util.Map;
|
|||
|
||||
public class PercentileRanksAggregationBuilder extends AbstractPercentilesAggregationBuilder<PercentileRanksAggregationBuilder> {
|
||||
public static final String NAME = PercentileRanks.TYPE_NAME;
|
||||
public static final ValuesSourceRegistry.RegistryKey<PercentilesAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, PercentilesAggregatorSupplier.class);
|
||||
|
||||
private static final ParseField VALUES_FIELD = new ParseField("values");
|
||||
private static final ConstructingObjectParser<PercentileRanksAggregationBuilder, String> PARSER;
|
||||
|
@ -105,4 +107,9 @@ public class PercentileRanksAggregationBuilder extends AbstractPercentilesAggreg
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,15 +20,11 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
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;
|
||||
|
@ -45,19 +41,13 @@ class PercentileRanksAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
private final boolean keyed;
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(PercentileRanksAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
PercentileRanksAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
new PercentilesAggregatorSupplier() {
|
||||
@Override
|
||||
public Aggregator build(String name, ValuesSource valuesSource, SearchContext context, Aggregator parent,
|
||||
double[] percents, PercentilesConfig percentilesConfig, boolean keyed, DocValueFormat formatter,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
|
||||
return percentilesConfig.createPercentileRanksAggregator(name, valuesSource, context, parent, percents, keyed,
|
||||
formatter, metadata);
|
||||
}
|
||||
}
|
||||
);
|
||||
(name, valuesSource, context, parent, percents, percentilesConfig, keyed, formatter,
|
||||
metadata) -> percentilesConfig
|
||||
.createPercentileRanksAggregator(name, valuesSource, context, parent, percents, keyed, formatter, metadata),
|
||||
true);
|
||||
}
|
||||
|
||||
PercentileRanksAggregatorFactory(String name,
|
||||
|
@ -85,28 +75,14 @@ class PercentileRanksAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound bucketCardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
PercentileRanksAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof PercentilesAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected PercentilesAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
PercentilesAggregatorSupplier percentilesAggregatorSupplier = (PercentilesAggregatorSupplier) aggregatorSupplier;
|
||||
return percentilesAggregatorSupplier.build(
|
||||
name,
|
||||
config.getValuesSource(),
|
||||
searchContext,
|
||||
parent,
|
||||
percents,
|
||||
percentilesConfig,
|
||||
keyed,
|
||||
config.format(),
|
||||
metadata
|
||||
);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound bucketCardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(PercentileRanksAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config.getValuesSource(), searchContext, parent, percents, percentilesConfig, keyed, config.format(), metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ import java.util.Map;
|
|||
|
||||
public class PercentilesAggregationBuilder extends AbstractPercentilesAggregationBuilder<PercentilesAggregationBuilder> {
|
||||
public static final String NAME = Percentiles.TYPE_NAME;
|
||||
public static final ValuesSourceRegistry.RegistryKey<PercentilesAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, PercentilesAggregatorSupplier.class);
|
||||
|
||||
private static final double[] DEFAULT_PERCENTS = new double[] { 1, 5, 25, 50, 75, 95, 99 };
|
||||
private static final ParseField PERCENTS_FIELD = new ParseField("percents");
|
||||
|
@ -139,4 +141,9 @@ public class PercentilesAggregationBuilder extends AbstractPercentilesAggregatio
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,15 +20,11 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
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;
|
||||
|
@ -49,19 +45,13 @@ class PercentilesAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
private final boolean keyed;
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(PercentilesAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
PercentilesAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
new PercentilesAggregatorSupplier() {
|
||||
@Override
|
||||
public Aggregator build(String name, ValuesSource valuesSource, SearchContext context, Aggregator parent,
|
||||
double[] percents, PercentilesConfig percentilesConfig, boolean keyed, DocValueFormat formatter,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
|
||||
return percentilesConfig.createPercentilesAggregator(name, valuesSource, context, parent, percents, keyed,
|
||||
formatter, metadata);
|
||||
}
|
||||
}
|
||||
);
|
||||
(name, valuesSource, context, parent, percents, percentilesConfig, keyed, formatter,
|
||||
metadata) -> percentilesConfig
|
||||
.createPercentilesAggregator(name, valuesSource, context, parent, percents, keyed, formatter, metadata),
|
||||
true);
|
||||
}
|
||||
|
||||
PercentilesAggregatorFactory(String name, ValuesSourceConfig config, double[] percents,
|
||||
|
@ -84,29 +74,14 @@ class PercentilesAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound bucketCardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
PercentilesAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof PercentilesAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected PercentilesAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
PercentilesAggregatorSupplier percentilesAggregatorSupplier = (PercentilesAggregatorSupplier) aggregatorSupplier;
|
||||
return percentilesAggregatorSupplier.build(
|
||||
name,
|
||||
config.getValuesSource(),
|
||||
searchContext,
|
||||
parent,
|
||||
percents,
|
||||
percentilesConfig,
|
||||
keyed,
|
||||
config.format(),
|
||||
metadata
|
||||
);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound bucketCardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(PercentilesAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config.getValuesSource(), searchContext, parent, percents, percentilesConfig, keyed, config.format(), metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,13 @@ 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.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface PercentilesAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface PercentilesAggregatorSupplier {
|
||||
Aggregator build(String name,
|
||||
ValuesSource valuesSource,
|
||||
SearchContext context,
|
||||
|
|
|
@ -39,6 +39,10 @@ import java.util.Map;
|
|||
|
||||
public class StatsAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource.Numeric, StatsAggregationBuilder> {
|
||||
public static final String NAME = "stats";
|
||||
public static final ValuesSourceRegistry.RegistryKey<MetricAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
MetricAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<StatsAggregationBuilder, String> PARSER =
|
||||
ObjectParser.fromBuilder(NAME, StatsAggregationBuilder::new);
|
||||
|
@ -97,4 +101,9 @@ public class StatsAggregationBuilder extends ValuesSourceAggregationBuilder.Leaf
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -47,9 +45,11 @@ class StatsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(StatsAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
StatsAggregationBuilder.REGISTRY_KEY,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
(MetricAggregatorSupplier) StatsAggregator::new);
|
||||
StatsAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,17 +60,14 @@ class StatsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
StatsAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(StatsAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config, searchContext, parent, metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,10 @@ import java.util.Map;
|
|||
|
||||
public class SumAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource.Numeric, SumAggregationBuilder> {
|
||||
public static final String NAME = "sum";
|
||||
public static final ValuesSourceRegistry.RegistryKey<MetricAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
MetricAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<SumAggregationBuilder, String> PARSER = ObjectParser.fromBuilder(NAME, SumAggregationBuilder::new);
|
||||
static {
|
||||
|
@ -97,4 +101,9 @@ public class SumAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOn
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -47,9 +45,11 @@ class SumAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(SumAggregationBuilder.NAME,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
(MetricAggregatorSupplier) SumAggregator::new);
|
||||
builder.register(
|
||||
SumAggregationBuilder.REGISTRY_KEY,
|
||||
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
|
||||
SumAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,17 +61,14 @@ class SumAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound bucketCardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
SumAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, searchContext, parent, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound bucketCardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(SumAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config, searchContext, parent, metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,10 @@ import java.util.Map;
|
|||
|
||||
public class ValueCountAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource, ValueCountAggregationBuilder> {
|
||||
public static final String NAME = "value_count";
|
||||
public static final ValuesSourceRegistry.RegistryKey<MetricAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
MetricAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<ValueCountAggregationBuilder, String> PARSER =
|
||||
ObjectParser.fromBuilder(NAME, ValueCountAggregationBuilder::new);
|
||||
|
@ -104,4 +108,9 @@ public class ValueCountAggregationBuilder extends ValuesSourceAggregationBuilder
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
package org.elasticsearch.search.aggregations.metrics;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -38,8 +36,7 @@ import java.util.Map;
|
|||
class ValueCountAggregatorFactory extends ValuesSourceAggregatorFactory {
|
||||
|
||||
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(ValueCountAggregationBuilder.NAME, CoreValuesSourceType.ALL_CORE,
|
||||
(MetricAggregatorSupplier) ValueCountAggregator::new);
|
||||
builder.register(ValueCountAggregationBuilder.REGISTRY_KEY, CoreValuesSourceType.ALL_CORE, ValueCountAggregator::new, true);
|
||||
}
|
||||
|
||||
ValueCountAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext,
|
||||
|
@ -56,17 +53,14 @@ class ValueCountAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound bucketCardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
ValueCountAggregationBuilder.NAME);
|
||||
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((MetricAggregatorSupplier) aggregatorSupplier)
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound bucketCardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(ValueCountAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config, searchContext, parent, metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,38 +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.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 {
|
||||
}
|
|
@ -346,15 +346,21 @@ public abstract class ValuesSourceAggregationBuilder<AB extends ValuesSourceAggr
|
|||
protected final ValuesSourceAggregatorFactory doBuild(QueryShardContext queryShardContext, AggregatorFactory parent,
|
||||
Builder subFactoriesBuilder) throws IOException {
|
||||
ValuesSourceConfig config = resolveConfig(queryShardContext);
|
||||
if (queryShardContext.getValuesSourceRegistry().isRegistered(getType())) {
|
||||
// Only test if the values source type is valid if the aggregation uses the registry
|
||||
AggregatorSupplier supplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, getType());
|
||||
if (queryShardContext.getValuesSourceRegistry().isRegistered(getRegistryKey())) {
|
||||
/*
|
||||
if the aggregation uses the values source registry, test if the resolved values source type is compatible with this aggregation.
|
||||
This call will throw if the mapping isn't registered, which is what we want. Note that we need to throw from here because
|
||||
AbstractAggregationBuilder#build, which called this, will attempt to register the agg usage next, and if the usage is invalid
|
||||
that will fail with a weird error.
|
||||
*/
|
||||
queryShardContext.getValuesSourceRegistry().getAggregator(getRegistryKey(), config);
|
||||
}
|
||||
// TODO: We should pass the supplier in from here. Right now this just checks that the VST is valid
|
||||
ValuesSourceAggregatorFactory factory = innerBuild(queryShardContext, config, parent, subFactoriesBuilder);
|
||||
return factory;
|
||||
}
|
||||
|
||||
protected abstract ValuesSourceRegistry.RegistryKey<?> getRegistryKey();
|
||||
|
||||
/**
|
||||
* Aggregations should use this method to define a {@link ValuesSourceType} of last resort. This will only be used when the resolver
|
||||
* can't find a field and the user hasn't provided a value type hint.
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.support;
|
|||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.SearchModule;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
|
@ -33,18 +32,14 @@ import java.util.Objects;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* {@link ValuesSourceRegistry} holds the mapping from {@link ValuesSourceType}s to {@link AggregatorSupplier}s. DO NOT directly
|
||||
* instantiate this class, instead get an already-configured copy from {@link QueryShardContext#getValuesSourceRegistry()}, or (in the case
|
||||
* of some test scenarios only) directly from {@link SearchModule#getValuesSourceRegistry()}
|
||||
* {@link ValuesSourceRegistry} holds the mapping from {@link ValuesSourceType}s to functions for building aggregation components. DO NOT
|
||||
* directly instantiate this class, instead get an already-configured copy from {@link QueryShardContext#getValuesSourceRegistry()}, or (in
|
||||
* the case of some test scenarios only) directly from {@link SearchModule#getValuesSourceRegistry()}
|
||||
*
|
||||
*/
|
||||
public class ValuesSourceRegistry {
|
||||
|
||||
public interface CompositeSupplier {
|
||||
// this interface intentionally left blank
|
||||
}
|
||||
|
||||
public static final class RegistryKey<T extends CompositeSupplier> {
|
||||
public static final class RegistryKey<T> {
|
||||
private final String name;
|
||||
private final Class<T> supplierType;
|
||||
|
||||
|
@ -71,11 +66,11 @@ public class ValuesSourceRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
public static final RegistryKey UNREGISTERED_KEY = new RegistryKey("unregistered", RegistryKey.class);
|
||||
|
||||
public static class Builder {
|
||||
private final AggregationUsageService.Builder usageServiceBuilder;
|
||||
private Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> aggregatorRegistry = new HashMap<>();
|
||||
private Map<RegistryKey<? extends CompositeSupplier>, List<Map.Entry<ValuesSourceType, CompositeSupplier>>> compositeRegistry =
|
||||
new HashMap<>();
|
||||
private Map<RegistryKey<?>, List<Map.Entry<ValuesSourceType, ?>>> aggregatorRegistry = new HashMap<>();
|
||||
|
||||
public Builder() {
|
||||
this.usageServiceBuilder = new AggregationUsageService.Builder();
|
||||
|
@ -85,73 +80,46 @@ public class ValuesSourceRegistry {
|
|||
/**
|
||||
* Register a ValuesSource to Aggregator mapping. This method registers mappings that only apply to a
|
||||
* single {@link ValuesSourceType}
|
||||
* @param aggregationName The name of the family of aggregations, typically found via
|
||||
* {@link ValuesSourceAggregationBuilder#getType()}
|
||||
* @param registryKey The name of the family of aggregations paired with the expected component supplier type for this
|
||||
* family of aggregations. Generally, the aggregation builder is expected to define a constant for use as the
|
||||
* registryKey
|
||||
* @param valuesSourceType The ValuesSourceType this mapping applies to.
|
||||
* @param aggregatorSupplier An Aggregation-specific specialization of AggregatorSupplier which will construct the mapped aggregator
|
||||
* from the aggregation standard set of parameters
|
||||
* @param aggregatorSupplier An Aggregation-specific specialization of ComponentSupplier which will construct the mapped aggregator
|
||||
* @param registerUsage Flag to indicate if this aggregation values source combo should be added to the usage registry.
|
||||
* Aggregations that set this to false should register with the usage registry through some other path.
|
||||
*/
|
||||
public void register(String aggregationName, ValuesSourceType valuesSourceType,
|
||||
AggregatorSupplier aggregatorSupplier) {
|
||||
if (aggregatorRegistry.containsKey(aggregationName) == false) {
|
||||
aggregatorRegistry.put(aggregationName, new ArrayList<>());
|
||||
public <T> void register(
|
||||
RegistryKey<T> registryKey,
|
||||
ValuesSourceType valuesSourceType,
|
||||
T aggregatorSupplier,
|
||||
boolean registerUsage) {
|
||||
if (aggregatorRegistry.containsKey(registryKey) == false) {
|
||||
aggregatorRegistry.put(registryKey, new ArrayList<>());
|
||||
}
|
||||
aggregatorRegistry.get(registryKey).add(new AbstractMap.SimpleEntry<>(valuesSourceType, aggregatorSupplier));
|
||||
if (registerUsage) {
|
||||
registerUsage(registryKey.getName(), valuesSourceType);
|
||||
}
|
||||
aggregatorRegistry.get(aggregationName).add(new AbstractMap.SimpleEntry<>(valuesSourceType, aggregatorSupplier));
|
||||
registerUsage(aggregationName, valuesSourceType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a ValuesSource to Aggregator mapping. This version provides a convenience method for mappings that apply to a
|
||||
* known list of {@link ValuesSourceType}
|
||||
* @param aggregationName The name of the family of aggregations, typically found via
|
||||
* {@link ValuesSourceAggregationBuilder#getType()}
|
||||
* @param registryKey The name of the family of aggregations paired with the expected component supplier type for this
|
||||
* family of aggregations. Generally, the aggregation builder is expected to define a constant for use as the
|
||||
* registryKey
|
||||
* @param valuesSourceTypes The ValuesSourceTypes this mapping applies to.
|
||||
* @param aggregatorSupplier An Aggregation-specific specialization of AggregatorSupplier which will construct the mapped aggregator
|
||||
* from the aggregation standard set of parameters
|
||||
* @param aggregatorSupplier An Aggregation-specific specialization of ComponentSupplier which will construct the mapped aggregator
|
||||
* @param registerUsage Flag to indicate if this aggregation values source combo should be added to the usage registry.
|
||||
* Aggregations that set this to false should register with the usage registry through some other path.
|
||||
*/
|
||||
public void register(String aggregationName, List<ValuesSourceType> valuesSourceTypes, AggregatorSupplier aggregatorSupplier) {
|
||||
for (ValuesSourceType valuesSourceType : valuesSourceTypes) {
|
||||
register(aggregationName, valuesSourceType, aggregatorSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new key generation function for the
|
||||
* {@link org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregation}.
|
||||
* @param registryKey the subclass of {@link CompositeSupplier} associated with the {@link CompositeValuesSourceBuilder} type this
|
||||
* mapping is being registered for, paired with the name of the key type.
|
||||
* @param valuesSourceType the {@link ValuesSourceType} this mapping applies to
|
||||
* @param compositeSupplier A function returning an appropriate
|
||||
* {@link org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceConfig}
|
||||
*/
|
||||
public <T extends CompositeSupplier> void registerComposite(
|
||||
RegistryKey<T> registryKey,
|
||||
ValuesSourceType valuesSourceType,
|
||||
T compositeSupplier
|
||||
) {
|
||||
if (compositeRegistry.containsKey(registryKey) == false) {
|
||||
compositeRegistry.put(registryKey, new ArrayList<>());
|
||||
}
|
||||
compositeRegistry.get(registryKey).add(new AbstractMap.SimpleEntry<>(valuesSourceType, compositeSupplier));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new key generation function for the
|
||||
* {@link org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregation}. This is a convenience version to map
|
||||
* multiple types to the same supplier.
|
||||
* @param registryKey the subclass of {@link CompositeSupplier} associated with the {@link CompositeValuesSourceBuilder} type this
|
||||
* mapping is being registered for, paired with the name of the key type.
|
||||
* @param valuesSourceTypes the {@link ValuesSourceType}s this mapping applies to
|
||||
* @param compositeSupplier A function returning an appropriate
|
||||
* {@link org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceConfig}
|
||||
*/
|
||||
public <T extends CompositeSupplier> void registerComposite(
|
||||
public <T> void register(
|
||||
RegistryKey<T> registryKey,
|
||||
List<ValuesSourceType> valuesSourceTypes,
|
||||
T compositeSupplier
|
||||
) {
|
||||
T aggregatorSupplier,
|
||||
boolean registerUsage) {
|
||||
for (ValuesSourceType valuesSourceType : valuesSourceTypes) {
|
||||
registerComposite(registryKey, valuesSourceType, compositeSupplier);
|
||||
register(registryKey, valuesSourceType, aggregatorSupplier, registerUsage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,16 +132,18 @@ public class ValuesSourceRegistry {
|
|||
}
|
||||
|
||||
public ValuesSourceRegistry build() {
|
||||
return new ValuesSourceRegistry(aggregatorRegistry, compositeRegistry, usageServiceBuilder.build());
|
||||
return new ValuesSourceRegistry(aggregatorRegistry, usageServiceBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
private static <K, T> Map<K, Map<ValuesSourceType, T>> copyMap(Map<K, List<Map.Entry<ValuesSourceType, T>>> mutableMap) {
|
||||
private static Map<RegistryKey<?>, Map<ValuesSourceType, ?>> copyMap(
|
||||
Map<RegistryKey<?>, List<Map.Entry<ValuesSourceType, ?>>> mutableMap
|
||||
) {
|
||||
/*
|
||||
Make an immutatble copy of our input map. Since this is write once, read many, we'll spend a bit of extra time to shape this
|
||||
into a Map.of(), which is more read optimized than just using a hash map.
|
||||
*/
|
||||
Map<K, Map<ValuesSourceType, T>> tmp = new HashMap<>();
|
||||
Map<RegistryKey<?>, Map<ValuesSourceType, ?>> tmp = new HashMap<>();
|
||||
mutableMap.forEach((key, value) -> tmp.put(key, value.stream().collect(
|
||||
Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))));
|
||||
return Collections.unmodifiableMap(tmp);
|
||||
|
@ -181,52 +151,32 @@ public class ValuesSourceRegistry {
|
|||
|
||||
/** Maps Aggregation names to (ValuesSourceType, Supplier) pairs, keyed by ValuesSourceType */
|
||||
private final AggregationUsageService usageService;
|
||||
private final Map<String, Map<ValuesSourceType, AggregatorSupplier>> aggregatorRegistry;
|
||||
private Map<RegistryKey<? extends CompositeSupplier>, Map<ValuesSourceType, CompositeSupplier>> compositeRegistry;
|
||||
private final Map<RegistryKey<?>, Map<ValuesSourceType, ?>> aggregatorRegistry;
|
||||
|
||||
public ValuesSourceRegistry(Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> aggregatorRegistry,
|
||||
Map<RegistryKey<? extends CompositeSupplier>, List<Map.Entry<ValuesSourceType, CompositeSupplier>>> compositeRegistry,
|
||||
AggregationUsageService usageService) {
|
||||
public ValuesSourceRegistry(
|
||||
Map<RegistryKey<?>, List<Map.Entry<ValuesSourceType, ?>>> aggregatorRegistry,
|
||||
AggregationUsageService usageService
|
||||
) {
|
||||
this.usageService = usageService;
|
||||
this.aggregatorRegistry = copyMap(aggregatorRegistry);
|
||||
this.compositeRegistry = copyMap(compositeRegistry);
|
||||
}
|
||||
|
||||
private AggregatorSupplier findMatchingSuppier(ValuesSourceType valuesSourceType,
|
||||
Map<ValuesSourceType, AggregatorSupplier> supportedTypes) {
|
||||
return supportedTypes.get(valuesSourceType);
|
||||
public boolean isRegistered(RegistryKey<?> registryKey) {
|
||||
return aggregatorRegistry.containsKey(registryKey);
|
||||
}
|
||||
|
||||
public boolean isRegistered(String aggregationName) {
|
||||
return aggregatorRegistry.containsKey(aggregationName);
|
||||
}
|
||||
|
||||
public AggregatorSupplier getAggregator(ValuesSourceConfig valuesSourceConfig, String aggregationName) {
|
||||
if (aggregationName != null && aggregatorRegistry.containsKey(aggregationName)) {
|
||||
AggregatorSupplier supplier = findMatchingSuppier(
|
||||
valuesSourceConfig.valueSourceType(),
|
||||
aggregatorRegistry.get(aggregationName)
|
||||
);
|
||||
public <T> T getAggregator(RegistryKey<T> registryKey, ValuesSourceConfig valuesSourceConfig) {
|
||||
if (registryKey != null && aggregatorRegistry.containsKey(registryKey)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T supplier = (T) aggregatorRegistry.get(registryKey).get(valuesSourceConfig.valueSourceType());
|
||||
if (supplier == null) {
|
||||
throw new IllegalArgumentException(
|
||||
valuesSourceConfig.getDescription() + " is not supported for aggregation [" + aggregationName + "]"
|
||||
valuesSourceConfig.getDescription() + " is not supported for aggregation [" + registryKey.getName() + "]"
|
||||
);
|
||||
}
|
||||
return supplier;
|
||||
}
|
||||
throw new AggregationExecutionException("Unregistered Aggregation [" + aggregationName + "]");
|
||||
}
|
||||
|
||||
public <T extends CompositeSupplier> T getComposite(RegistryKey<T> registryKey, ValuesSourceConfig config) {
|
||||
if (registryKey != null && compositeRegistry.containsKey(registryKey)) {
|
||||
CompositeSupplier supplier = compositeRegistry.get(registryKey).get(config.valueSourceType());
|
||||
if (supplier == null) {
|
||||
throw new IllegalArgumentException(config.getDescription() + " is not supported for composite source [" +
|
||||
registryKey.getName() + "]");
|
||||
}
|
||||
return (T) supplier; // Safe because we checked the type matched the key at load time
|
||||
}
|
||||
throw new AggregationExecutionException("Unregistered composite source [" + registryKey.getName() + "]");
|
||||
throw new AggregationExecutionException("Unregistered Aggregation [" + registryKey.getName() + "]");
|
||||
}
|
||||
|
||||
public AggregationUsageService getUsageService() {
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
|||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
|
||||
import org.elasticsearch.search.fetch.FetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.subphase.ExplainPhase;
|
||||
|
@ -398,6 +399,11 @@ public class SearchModuleTests extends ESTestCase {
|
|||
return "test";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return ValuesSourceRegistry.UNREGISTERED_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void innerWriteTo(StreamOutput out) throws IOException {
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.search.aggregations.support;
|
|||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.script.AggregationScript;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregatorSupplier;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -58,13 +59,12 @@ public class ValuesSourceRegistryTests extends ESTestCase {
|
|||
null,
|
||||
CoreValuesSourceType.BYTES
|
||||
);
|
||||
ValuesSourceRegistry.RegistryKey key = new ValuesSourceRegistry.RegistryKey("bogus", HistogramAggregatorSupplier.class);
|
||||
ValuesSourceRegistry registry = new ValuesSourceRegistry(
|
||||
Collections.singletonMap("bogus", Collections.emptyList()),
|
||||
Collections.singletonMap(new ValuesSourceRegistry.RegistryKey<>("bogus", ValuesSourceRegistry.CompositeSupplier.class),
|
||||
Collections.emptyList()),
|
||||
Collections.singletonMap(key, Collections.emptyList()),
|
||||
null
|
||||
);
|
||||
expectThrows(IllegalArgumentException.class, () -> registry.getAggregator(fieldOnly, "bogus"));
|
||||
expectThrows(IllegalArgumentException.class, () -> registry.getAggregator(scriptOnly, "bogus"));
|
||||
expectThrows(IllegalArgumentException.class, () -> registry.getAggregator(key, fieldOnly));
|
||||
expectThrows(IllegalArgumentException.class, () -> registry.getAggregator(key, scriptOnly));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,9 @@
|
|||
package org.elasticsearch.xpack.analytics.aggregations;
|
||||
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.metrics.AvgAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.MetricAggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.metrics.PercentileRanksAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.PercentilesAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.PercentilesAggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.metrics.PercentilesConfig;
|
||||
import org.elasticsearch.search.aggregations.metrics.PercentilesMethod;
|
||||
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
|
||||
|
@ -30,11 +27,9 @@ import org.elasticsearch.xpack.analytics.aggregations.support.AnalyticsValuesSou
|
|||
public class AnalyticsAggregatorFactory {
|
||||
|
||||
public static void registerPercentilesAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(PercentilesAggregationBuilder.NAME,
|
||||
builder.register(PercentilesAggregationBuilder.REGISTRY_KEY,
|
||||
AnalyticsValuesSourceType.HISTOGRAM,
|
||||
(PercentilesAggregatorSupplier) (name, valuesSource, context, parent, percents, percentilesConfig, keyed,
|
||||
formatter, metadata) -> {
|
||||
|
||||
(name, valuesSource, context, parent, percents, percentilesConfig, keyed, formatter, metadata) -> {
|
||||
if (percentilesConfig.getMethod().equals(PercentilesMethod.TDIGEST)) {
|
||||
double compression = ((PercentilesConfig.TDigest)percentilesConfig).getCompression();
|
||||
return new HistoBackedTDigestPercentilesAggregator(name, valuesSource, context, parent,
|
||||
|
@ -48,15 +43,13 @@ public class AnalyticsAggregatorFactory {
|
|||
|
||||
throw new IllegalArgumentException("Percentiles algorithm: [" + percentilesConfig.getMethod().toString() + "] " +
|
||||
"is not compatible with Histogram field");
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
|
||||
public static void registerPercentileRanksAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(PercentileRanksAggregationBuilder.NAME,
|
||||
builder.register(PercentileRanksAggregationBuilder.REGISTRY_KEY,
|
||||
AnalyticsValuesSourceType.HISTOGRAM,
|
||||
(PercentilesAggregatorSupplier) (name, valuesSource, context, parent, percents, percentilesConfig, keyed,
|
||||
formatter, metadata) -> {
|
||||
|
||||
(name, valuesSource, context, parent, percents, percentilesConfig, keyed, formatter, metadata) -> {
|
||||
if (percentilesConfig.getMethod().equals(PercentilesMethod.TDIGEST)) {
|
||||
double compression = ((PercentilesConfig.TDigest)percentilesConfig).getCompression();
|
||||
return new HistoBackedTDigestPercentileRanksAggregator(name, valuesSource, context, parent,
|
||||
|
@ -70,34 +63,28 @@ public class AnalyticsAggregatorFactory {
|
|||
|
||||
throw new IllegalArgumentException("Percentiles algorithm: [" + percentilesConfig.getMethod().toString() + "] " +
|
||||
"is not compatible with Histogram field");
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
|
||||
public static void registerHistoBackedSumAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(SumAggregationBuilder.NAME,
|
||||
AnalyticsValuesSourceType.HISTOGRAM,
|
||||
(MetricAggregatorSupplier) HistoBackedSumAggregator::new
|
||||
);
|
||||
builder.register(SumAggregationBuilder.REGISTRY_KEY, AnalyticsValuesSourceType.HISTOGRAM, HistoBackedSumAggregator::new, true);
|
||||
}
|
||||
|
||||
public static void registerHistoBackedValueCountAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(ValueCountAggregationBuilder.NAME,
|
||||
builder.register(ValueCountAggregationBuilder.REGISTRY_KEY,
|
||||
AnalyticsValuesSourceType.HISTOGRAM,
|
||||
(MetricAggregatorSupplier) HistoBackedValueCountAggregator::new
|
||||
);
|
||||
HistoBackedValueCountAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
public static void registerHistoBackedAverageAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(AvgAggregationBuilder.NAME,
|
||||
AnalyticsValuesSourceType.HISTOGRAM,
|
||||
(MetricAggregatorSupplier) HistoBackedAvgAggregator::new
|
||||
);
|
||||
builder.register(AvgAggregationBuilder.REGISTRY_KEY, AnalyticsValuesSourceType.HISTOGRAM, HistoBackedAvgAggregator::new, true);
|
||||
}
|
||||
|
||||
public static void registerHistoBackedHistogramAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(HistogramAggregationBuilder.NAME,
|
||||
builder.register(HistogramAggregationBuilder.REGISTRY_KEY,
|
||||
AnalyticsValuesSourceType.HISTOGRAM,
|
||||
(HistogramAggregatorSupplier) HistoBackedHistogramAggregator::new
|
||||
);
|
||||
HistoBackedHistogramAggregator::new,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,12 @@ import java.util.Objects;
|
|||
|
||||
import static org.elasticsearch.search.aggregations.metrics.PercentilesMethod.COMPRESSION_FIELD;
|
||||
|
||||
public class BoxplotAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource,
|
||||
BoxplotAggregationBuilder> {
|
||||
public class BoxplotAggregationBuilder extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource, BoxplotAggregationBuilder> {
|
||||
public static final String NAME = "boxplot";
|
||||
public static final ValuesSourceRegistry.RegistryKey<BoxplotAggregatorSupplier> REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>(
|
||||
NAME,
|
||||
BoxplotAggregatorSupplier.class
|
||||
);
|
||||
|
||||
public static final ObjectParser<BoxplotAggregationBuilder, String> PARSER =
|
||||
ObjectParser.fromBuilder(NAME, BoxplotAggregationBuilder::new);
|
||||
|
@ -131,5 +134,10 @@ public class BoxplotAggregationBuilder extends ValuesSourceAggregationBuilder.Le
|
|||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,10 @@
|
|||
package org.elasticsearch.xpack.analytics.boxplot;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -29,9 +27,11 @@ public class BoxplotAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
private final double compression;
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(BoxplotAggregationBuilder.NAME,
|
||||
builder.register(
|
||||
BoxplotAggregationBuilder.REGISTRY_KEY,
|
||||
Arrays.asList(CoreValuesSourceType.NUMERIC, AnalyticsValuesSourceType.HISTOGRAM),
|
||||
(BoxplotAggregatorSupplier) BoxplotAggregator::new);
|
||||
BoxplotAggregator::new,
|
||||
true);
|
||||
}
|
||||
|
||||
BoxplotAggregatorFactory(String name,
|
||||
|
@ -54,18 +54,14 @@ public class BoxplotAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Aggregator doCreateInternal(SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
BoxplotAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof BoxplotAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected BoxplotAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((BoxplotAggregatorSupplier) aggregatorSupplier).build(name, config.getValuesSource(), config.format(), compression,
|
||||
searchContext, parent, metadata);
|
||||
protected Aggregator doCreateInternal(
|
||||
SearchContext searchContext,
|
||||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata
|
||||
) throws IOException {
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(BoxplotAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config.getValuesSource(), config.format(), compression, searchContext, parent, metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.elasticsearch.xpack.analytics.boxplot;
|
|||
|
||||
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.internal.SearchContext;
|
||||
|
||||
|
@ -16,7 +15,7 @@ import java.io.IOException;
|
|||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BoxplotAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface BoxplotAggregatorSupplier {
|
||||
Aggregator build(String name,
|
||||
ValuesSource valuesSource,
|
||||
DocValueFormat formatter,
|
||||
|
|
|
@ -27,6 +27,8 @@ import java.util.Objects;
|
|||
public class StringStatsAggregationBuilder extends ValuesSourceAggregationBuilder<StringStatsAggregationBuilder> {
|
||||
|
||||
public static final String NAME = "string_stats";
|
||||
public static final ValuesSourceRegistry.RegistryKey<StringStatsAggregatorSupplier> REGISTRY_KEY =
|
||||
new ValuesSourceRegistry.RegistryKey<>(NAME, StringStatsAggregatorSupplier.class);
|
||||
|
||||
private static final ParseField SHOW_DISTRIBUTION_FIELD = new ParseField("show_distribution");
|
||||
public static final ObjectParser<StringStatsAggregationBuilder, String> PARSER =
|
||||
|
@ -95,6 +97,11 @@ public class StringStatsAggregationBuilder extends ValuesSourceAggregationBuilde
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return REGISTRY_KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether to include the probability distribution of each character in the results.
|
||||
* {@code showDistribution} is true, distribution will be included.
|
||||
|
|
|
@ -7,12 +7,10 @@
|
|||
package org.elasticsearch.xpack.analytics.stringstats;
|
||||
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
|
||||
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
|
||||
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
@ -36,8 +34,9 @@ class StringStatsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
}
|
||||
|
||||
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(StringStatsAggregationBuilder.NAME,
|
||||
CoreValuesSourceType.BYTES, (StringStatsAggregatorSupplier) StringStatsAggregator::new);
|
||||
builder.register(
|
||||
StringStatsAggregationBuilder.REGISTRY_KEY,
|
||||
CoreValuesSourceType.BYTES, StringStatsAggregator::new, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,15 +51,9 @@ class StringStatsAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|||
Aggregator parent,
|
||||
CardinalityUpperBound cardinality,
|
||||
Map<String, Object> metadata) throws IOException {
|
||||
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
|
||||
StringStatsAggregationBuilder.NAME);
|
||||
|
||||
if (aggregatorSupplier instanceof StringStatsAggregatorSupplier == false) {
|
||||
throw new AggregationExecutionException("Registry miss-match - expected StringStatsAggregatorSupplier, found [" +
|
||||
aggregatorSupplier.getClass().toString() + "]");
|
||||
}
|
||||
return ((StringStatsAggregatorSupplier) aggregatorSupplier).build(name, config.getValuesSource(), showDistribution, config.format(),
|
||||
searchContext, parent, metadata);
|
||||
return queryShardContext.getValuesSourceRegistry()
|
||||
.getAggregator(StringStatsAggregationBuilder.REGISTRY_KEY, config)
|
||||
.build(name, config.getValuesSource(), showDistribution, config.format(), searchContext, parent, metadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,14 +7,13 @@ package org.elasticsearch.xpack.analytics.stringstats;
|
|||
|
||||
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.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface StringStatsAggregatorSupplier extends AggregatorSupplier {
|
||||
public interface StringStatsAggregatorSupplier {
|
||||
|
||||
Aggregator build(String name,
|
||||
ValuesSource valuesSource,
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
|
|||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -64,6 +65,11 @@ public class MockDeprecatedAggregationBuilder extends ValuesSourceAggregationBui
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
|
||||
return ValuesSourceRegistry.UNREGISTERED_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void innerWriteTo(StreamOutput out) throws IOException {
|
||||
}
|
||||
|
|
|
@ -18,12 +18,8 @@ import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridAggregati
|
|||
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileGridAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.CardinalityAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.CardinalityAggregator;
|
||||
import org.elasticsearch.search.aggregations.metrics.CardinalityAggregatorSupplier;
|
||||
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.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.support.ValuesSourceRegistry;
|
||||
|
@ -99,24 +95,30 @@ public class SpatialPlugin extends GeoPlugin implements MapperPlugin, SearchPlug
|
|||
}
|
||||
|
||||
private static void registerGeoShapeBoundsAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(GeoBoundsAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(),
|
||||
(GeoBoundsAggregatorSupplier) GeoShapeBoundsAggregator::new);
|
||||
builder.register(
|
||||
GeoBoundsAggregationBuilder.REGISTRY_KEY,
|
||||
GeoShapeValuesSourceType.instance(),
|
||||
GeoShapeBoundsAggregator::new,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
private void registerGeoShapeCentroidAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(GeoCentroidAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(),
|
||||
(MetricAggregatorSupplier) (name, valuesSourceConfig, aggregationContext, parent, metadata)
|
||||
builder.register(GeoCentroidAggregationBuilder.REGISTRY_KEY, GeoShapeValuesSourceType.instance(),
|
||||
(name, valuesSourceConfig, aggregationContext, parent, metadata)
|
||||
-> {
|
||||
if (getLicenseState().checkFeature(XPackLicenseState.Feature.SPATIAL_GEO_CENTROID)) {
|
||||
return new GeoShapeCentroidAggregator(name, aggregationContext, parent, valuesSourceConfig, metadata);
|
||||
}
|
||||
throw LicenseUtils.newComplianceException("geo_centroid aggregation on geo_shape fields");
|
||||
});
|
||||
},
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
private void registerGeoShapeGridAggregators(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(GeoHashGridAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(),
|
||||
(GeoGridAggregatorSupplier) (name, factories, valuesSource, precision, geoBoundingBox, requiredSize, shardSize,
|
||||
builder.register(GeoHashGridAggregationBuilder.REGISTRY_KEY, GeoShapeValuesSourceType.instance(),
|
||||
(name, factories, valuesSource, precision, geoBoundingBox, requiredSize, shardSize,
|
||||
aggregationContext, parent, collectsFromSingleBucket, metadata) -> {
|
||||
if (getLicenseState().checkFeature(XPackLicenseState.Feature.SPATIAL_GEO_GRID)) {
|
||||
final GeoGridTiler tiler;
|
||||
|
@ -133,10 +135,12 @@ public class SpatialPlugin extends GeoPlugin implements MapperPlugin, SearchPlug
|
|||
return agg;
|
||||
}
|
||||
throw LicenseUtils.newComplianceException("geohash_grid aggregation on geo_shape fields");
|
||||
});
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
builder.register(GeoTileGridAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(),
|
||||
(GeoGridAggregatorSupplier) (name, factories, valuesSource, precision, geoBoundingBox, requiredSize, shardSize,
|
||||
builder.register(GeoTileGridAggregationBuilder.REGISTRY_KEY, GeoShapeValuesSourceType.instance(),
|
||||
(name, factories, valuesSource, precision, geoBoundingBox, requiredSize, shardSize,
|
||||
aggregationContext, parent, collectsFromSingleBucket, metadata) -> {
|
||||
if (getLicenseState().checkFeature(XPackLicenseState.Feature.SPATIAL_GEO_GRID)) {
|
||||
final GeoGridTiler tiler;
|
||||
|
@ -153,17 +157,16 @@ public class SpatialPlugin extends GeoPlugin implements MapperPlugin, SearchPlug
|
|||
return agg;
|
||||
}
|
||||
throw LicenseUtils.newComplianceException("geotile_grid aggregation on geo_shape fields");
|
||||
});
|
||||
}
|
||||
|
||||
private static void registerValueCountAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(ValueCountAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(),
|
||||
(MetricAggregatorSupplier) ValueCountAggregator::new
|
||||
},
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
private static void registerValueCountAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(ValueCountAggregationBuilder.REGISTRY_KEY, GeoShapeValuesSourceType.instance(), ValueCountAggregator::new, true);
|
||||
}
|
||||
|
||||
private static void registerCardinalityAggregator(ValuesSourceRegistry.Builder builder) {
|
||||
builder.register(CardinalityAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(),
|
||||
(CardinalityAggregatorSupplier) CardinalityAggregator::new);
|
||||
builder.register(CardinalityAggregationBuilder.REGISTRY_KEY, GeoShapeValuesSourceType.instance(), CardinalityAggregator::new, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,9 +36,10 @@ public class SpatialPluginTests extends ESTestCase {
|
|||
List<Consumer<ValuesSourceRegistry.Builder>> registrar = plugin.getAggregationExtentions();
|
||||
registrar.forEach(c -> c.accept(registryBuilder));
|
||||
ValuesSourceRegistry registry = registryBuilder.build();
|
||||
MetricAggregatorSupplier centroidSupplier = (MetricAggregatorSupplier) registry.getAggregator(
|
||||
new ValuesSourceConfig(GeoShapeValuesSourceType.instance(), null, true, null, null, null, null, null, null),
|
||||
GeoCentroidAggregationBuilder.NAME);
|
||||
MetricAggregatorSupplier centroidSupplier = registry.getAggregator(
|
||||
GeoCentroidAggregationBuilder.REGISTRY_KEY,
|
||||
new ValuesSourceConfig(GeoShapeValuesSourceType.instance(), null, true, null, null, null, null, null, null)
|
||||
);
|
||||
if (License.OperationMode.TRIAL != operationMode &&
|
||||
License.OperationMode.compare(operationMode, License.OperationMode.GOLD) < 0) {
|
||||
ElasticsearchSecurityException exception = expectThrows(ElasticsearchSecurityException.class,
|
||||
|
@ -50,23 +51,28 @@ public class SpatialPluginTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testGeoGridLicenseCheck() {
|
||||
for (String builderName : Arrays.asList(GeoHashGridAggregationBuilder.NAME, GeoTileGridAggregationBuilder.NAME)) {
|
||||
for (ValuesSourceRegistry.RegistryKey<GeoGridAggregatorSupplier> registryKey : Arrays.asList(
|
||||
GeoHashGridAggregationBuilder.REGISTRY_KEY,
|
||||
GeoTileGridAggregationBuilder.REGISTRY_KEY
|
||||
)) {
|
||||
for (License.OperationMode operationMode : License.OperationMode.values()) {
|
||||
SpatialPlugin plugin = getPluginWithOperationMode(operationMode);
|
||||
ValuesSourceRegistry.Builder registryBuilder = new ValuesSourceRegistry.Builder();
|
||||
List<Consumer<ValuesSourceRegistry.Builder>> registrar = plugin.getAggregationExtentions();
|
||||
registrar.forEach(c -> c.accept(registryBuilder));
|
||||
ValuesSourceRegistry registry = registryBuilder.build();
|
||||
GeoGridAggregatorSupplier supplier = (GeoGridAggregatorSupplier) registry.getAggregator(
|
||||
new ValuesSourceConfig(GeoShapeValuesSourceType.instance(), null, true, null, null, null, null, null, null),
|
||||
builderName);
|
||||
GeoGridAggregatorSupplier supplier = registry.getAggregator(
|
||||
registryKey,
|
||||
new ValuesSourceConfig(GeoShapeValuesSourceType.instance(), null, true, null, null, null, null, null, null)
|
||||
);
|
||||
if (License.OperationMode.TRIAL != operationMode &&
|
||||
License.OperationMode.compare(operationMode, License.OperationMode.GOLD) < 0) {
|
||||
ElasticsearchSecurityException exception = expectThrows(ElasticsearchSecurityException.class,
|
||||
() -> supplier.build(null, null, null, 0, null,
|
||||
0,0, null, null, CardinalityUpperBound.NONE, null));
|
||||
assertThat(exception.getMessage(),
|
||||
equalTo("current license is non-compliant for [" + builderName + " aggregation on geo_shape fields]"));
|
||||
equalTo("current license is non-compliant for [" + registryKey.getName() + " aggregation on geo_shape fields]")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue