{"record":{"id":"2f4939f52fa93193","repo":"elastic/elasticsearch","slug":"cancelled-2f4939","errorCode":null,"errorMessage":"Cancelled","messagePattern":"Cancelled","errorType":"exception","errorClass":"TaskCancelledException","httpStatus":null,"severity":"error","filePath":"modules/aggregations/src/main/java/org/elasticsearch/aggregations/pipeline/BucketSelectorPipelineAggregator.java","lineNumber":54,"sourceCode":"        Script script,\n        GapPolicy gapPolicy,\n        Map<String, Object> metadata\n    ) {\n        super(name, bucketsPathsMap.values().toArray(new String[0]), metadata);\n        this.bucketsPathsMap = bucketsPathsMap;\n        this.script = script;\n        this.gapPolicy = gapPolicy;\n    }\n\n    @Override\n    public InternalAggregation reduce(InternalAggregation aggregation, AggregationReduceContext reduceContext) {\n        InternalMultiBucketAggregation<InternalMultiBucketAggregation<?, ?>, InternalMultiBucketAggregation.InternalBucket> originalAgg =\n            asMultiBucketAggregation(aggregation);\n        List<? extends InternalMultiBucketAggregation.InternalBucket> buckets = originalAgg.getBuckets();\n\n        BucketAggregationSelectorScript.Factory factory = reduceContext.scriptService()\n            .compile(script, BucketAggregationSelectorScript.CONTEXT);\n        Runnable cancellationCheck = () -> { if (reduceContext.isCanceled().get()) throw new TaskCancelledException(\"Cancelled\"); };\n        List<InternalMultiBucketAggregation.InternalBucket> newBuckets = new ArrayList<>();\n        for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) {\n            Map<String, Object> vars = new HashMap<>();\n            if (script.getParams() != null) {\n                vars.putAll(script.getParams());\n            }\n            for (Map.Entry<String, String> entry : bucketsPathsMap.entrySet()) {\n                String varName = entry.getKey();\n                String bucketsPath = entry.getValue();\n                Double value = resolveBucketValue(originalAgg, bucket, bucketsPath, gapPolicy);\n                vars.put(varName, value);\n            }\n            // TODO: can we use one instance of the script for all buckets? it should be stateless?\n            BucketAggregationSelectorScript executableScript = factory.newInstance(vars);\n            executableScript._setCancellationCheck(cancellationCheck);\n            if (executableScript.execute()) {\n                newBuckets.add(bucket);\n            }","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/aggregations/src/main/java/org/elasticsearch/aggregations/pipeline/BucketSelectorPipelineAggregator.java#L36-L72","documentation":"Error \"Cancelled\" thrown in elastic/elasticsearch.","triggerScenarios":"Thrown at modules/aggregations/src/main/java/org/elasticsearch/aggregations/pipeline/BucketSelectorPipelineAggregator.java:54 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}