|
@@ -34,18 +34,27 @@ import org.elasticsearch.search.aggregations.Aggregator;
|
|
|
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
|
|
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
|
|
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;
|
|
|
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
|
|
+import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
|
|
|
import org.elasticsearch.search.internal.SearchContext;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.Map;
|
|
|
|
|
|
-import static org.elasticsearch.search.aggregations.support.AggregationUsageService.OTHER_SUBTYPE;
|
|
|
+public class GeoDistanceRangeAggregatorFactory extends ValuesSourceAggregatorFactory {
|
|
|
|
|
|
-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, metadata) -> {
|
|
|
+ DistanceSource distanceSource = new DistanceSource((ValuesSource.GeoPoint) valuesSource, distanceType, origin, units);
|
|
|
+ return new RangeAggregator(name, factories, distanceSource, format, rangeFactory, ranges, keyed, context, parent, metadata);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
private final InternalRange.Factory<InternalGeoDistance.Bucket, InternalGeoDistance> rangeFactory = InternalGeoDistance.FACTORY;
|
|
|
private final GeoPoint origin;
|
|
@@ -81,13 +90,14 @@ public class GeoDistanceRangeAggregatorFactory
|
|
|
Aggregator parent,
|
|
|
boolean collectsFromSingleBucket,
|
|
|
Map<String, Object> metadata) throws IOException {
|
|
|
- if (valuesSource instanceof ValuesSource.GeoPoint == false) {
|
|
|
- throw new AggregationExecutionException("ValuesSource type " + valuesSource.toString() + "is not supported for aggregation " +
|
|
|
- this.name());
|
|
|
+ AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
|
|
|
+ .getAggregator(config.valueSourceType(), GeoDistanceAggregationBuilder.NAME);
|
|
|
+ if (aggregatorSupplier instanceof GeoDistanceAggregatorSupplier == false) {
|
|
|
+ throw new AggregationExecutionException("Registry miss-match - expected "
|
|
|
+ + GeoDistanceAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]");
|
|
|
}
|
|
|
- DistanceSource distanceSource = new DistanceSource((ValuesSource.GeoPoint) valuesSource, distanceType, origin, unit);
|
|
|
- return new RangeAggregator(name, factories, distanceSource, config.format(), rangeFactory, ranges, keyed, searchContext,
|
|
|
- parent, metadata);
|
|
|
+ return ((GeoDistanceAggregatorSupplier) aggregatorSupplier).build(name, factories, distanceType, origin,
|
|
|
+ unit, config.toValuesSource(), config.format(), rangeFactory, ranges, keyed, searchContext, parent, metadata);
|
|
|
}
|
|
|
|
|
|
private static class DistanceSource extends ValuesSource.Numeric {
|
|
@@ -129,10 +139,4 @@ public class GeoDistanceRangeAggregatorFactory
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getStatsSubtype() {
|
|
|
- // GeoDistanceRangeAggregatorFactory doesn't register itself with ValuesSourceRegistry
|
|
|
- return OTHER_SUBTYPE;
|
|
|
- }
|
|
|
}
|