[Scripting] Use Number as a return value for BucketAggregationScript (#35653)
This change fixes #35351. Users were no longer able to return types of numbers other than doubles for bucket aggregation scripts. This change reverts to the previous behavior of being able to return any type of number and having it converted to a double outside of the script.
This commit is contained in:
parent
baf33b3162
commit
d62bbca56d
|
@ -109,7 +109,7 @@ public class ExpressionScriptEngine implements ScriptEngine {
|
|||
BucketAggregationSelectorScript.Factory wrappedFactory = parameters -> new BucketAggregationSelectorScript(parameters) {
|
||||
@Override
|
||||
public boolean execute() {
|
||||
return factory.newInstance(getParams()).execute() == 1.0;
|
||||
return factory.newInstance(getParams()).execute().doubleValue() == 1.0;
|
||||
}
|
||||
};
|
||||
return context.factoryClazz.cast(wrappedFactory);
|
||||
|
|
|
@ -46,7 +46,7 @@ public abstract class BucketAggregationScript {
|
|||
return params;
|
||||
}
|
||||
|
||||
public abstract Double execute();
|
||||
public abstract Number execute();
|
||||
|
||||
public interface Factory {
|
||||
BucketAggregationScript newInstance(Map<String, Object> params);
|
||||
|
|
|
@ -108,13 +108,13 @@ public class BucketScriptPipelineAggregator extends PipelineAggregator {
|
|||
if (skipBucket) {
|
||||
newBuckets.add(bucket);
|
||||
} else {
|
||||
Double returned = factory.newInstance(vars).execute();
|
||||
Number returned = factory.newInstance(vars).execute();
|
||||
if (returned == null) {
|
||||
newBuckets.add(bucket);
|
||||
} else {
|
||||
final List<InternalAggregation> aggs = StreamSupport.stream(bucket.getAggregations().spliterator(), false).map(
|
||||
(p) -> (InternalAggregation) p).collect(Collectors.toList());
|
||||
aggs.add(new InternalSimpleValue(name(), returned, formatter, new ArrayList<>(), metaData()));
|
||||
aggs.add(new InternalSimpleValue(name(), returned.doubleValue(), formatter, new ArrayList<>(), metaData()));
|
||||
InternalMultiBucketAggregation.InternalBucket newBucket = originalAgg.createBucket(new InternalAggregations(aggs),
|
||||
bucket);
|
||||
newBuckets.add(newBucket);
|
||||
|
|
Loading…
Reference in New Issue