File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
server/src/main/java/org/elasticsearch/search/aggregations/pipeline Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 2121import java .util .ArrayList ;
2222import java .util .HashMap ;
2323import java .util .List ;
24+ import java .util .Locale ;
2425import java .util .Map ;
2526
2627import static org .elasticsearch .search .aggregations .pipeline .BucketHelpers .resolveBucketValue ;
@@ -47,10 +48,24 @@ public class BucketScriptPipelineAggregator extends PipelineAggregator {
4748 }
4849
4950 @ Override
51+ @ SuppressWarnings ({ "rawtypes" , "unchecked" })
5052 public InternalAggregation reduce (InternalAggregation aggregation , AggregationReduceContext reduceContext ) {
51- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
52- InternalMultiBucketAggregation <InternalMultiBucketAggregation , InternalMultiBucketAggregation .InternalBucket > originalAgg =
53- (InternalMultiBucketAggregation <InternalMultiBucketAggregation , InternalMultiBucketAggregation .InternalBucket >) aggregation ;
53+
54+ InternalMultiBucketAggregation <InternalMultiBucketAggregation , InternalMultiBucketAggregation .InternalBucket > originalAgg ;
55+
56+ if (aggregation instanceof InternalMultiBucketAggregation multiBucketAggregation ) {
57+ originalAgg = multiBucketAggregation ;
58+ } else {
59+ throw new IllegalArgumentException (
60+ String .format (
61+ Locale .ROOT ,
62+ "Expected a multi bucket aggregation but got [%s] for aggregation [%s]" ,
63+ aggregation .getClass ().getSimpleName (),
64+ name ()
65+ )
66+ );
67+ }
68+
5469 List <? extends InternalMultiBucketAggregation .InternalBucket > buckets = originalAgg .getBuckets ();
5570
5671 BucketAggregationScript .Factory factory = reduceContext .scriptService ().compile (script , BucketAggregationScript .CONTEXT );
You can’t perform that action at this time.
0 commit comments