Skip to content

Commit

Permalink
CR: Make BucketSelectorPipelineAggregator agnositc to lang
Browse files Browse the repository at this point in the history
  • Loading branch information
original-brownbear committed Jul 21, 2018
1 parent 05e6559 commit bc27466
Showing 1 changed file with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.script.BucketAggregationSelectorScript;
import org.elasticsearch.script.BucketAggregationScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext;
Expand Down Expand Up @@ -84,23 +83,12 @@ public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext
List<? extends InternalMultiBucketAggregation.InternalBucket> buckets = originalAgg.getBuckets();

List<InternalMultiBucketAggregation.InternalBucket> newBuckets = new ArrayList<>();
if ("expression".equals(script.getLang())) {
BucketAggregationScript.Factory factory =
reduceContext.scriptService().compile(script, BucketAggregationScript.CONTEXT);
BucketAggregationScript executableScript = factory.newInstance();
for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) {
if (executableScript.execute(scriptArgs(originalAgg, bucket)) == 1.0) {
newBuckets.add(bucket);
}
}
} else {
BucketAggregationSelectorScript.Factory factory =
reduceContext.scriptService().compile(script, BucketAggregationSelectorScript.CONTEXT);
BucketAggregationSelectorScript executableScript = factory.newInstance();
for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) {
if (executableScript.execute(scriptArgs(originalAgg, bucket))) {
newBuckets.add(bucket);
}
BucketAggregationSelectorScript.Factory factory =
reduceContext.scriptService().compile(script, BucketAggregationSelectorScript.CONTEXT);
BucketAggregationSelectorScript executableScript = factory.newInstance();
for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) {
if (executableScript.execute(scriptArgs(originalAgg, bucket))) {
newBuckets.add(bucket);
}
}
return originalAgg.create(newBuckets);
Expand Down

0 comments on commit bc27466

Please sign in to comment.