{"record":{"id":"d5494dbbb9490307","repo":"elastic/elasticsearch","slug":"error-evaluating","errorCode":null,"errorMessage":"Error evaluating {}","messagePattern":"Error evaluating (.+?)","errorType":"exception","errorClass":"GeneralScriptException","httpStatus":null,"severity":"error","filePath":"modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionAggregationScript.java","lineNumber":69,"sourceCode":"            // Fake the scorer until setScorer is called.\n            DoubleValues values = source.getValues(leaf, new DoubleValues() {\n                @Override\n                public double doubleValue() throws IOException {\n                    return get_score().doubleValue();\n                }\n\n                @Override\n                public boolean advanceExact(int doc) throws IOException {\n                    return true;\n                }\n            });\n\n            @Override\n            public Object execute() {\n                try {\n                    return values.doubleValue();\n                } catch (Exception exception) {\n                    throw new GeneralScriptException(\"Error evaluating \" + exprScript, exception);\n                }\n            }\n\n            @Override\n            public void setDocument(int d) {\n                try {\n                    values.advanceExact(d);\n                } catch (IOException e) {\n                    throw new IllegalStateException(\"Can't advance to doc using \" + exprScript, e);\n                }\n            }\n\n            @Override\n            public void setNextAggregationValue(Object value) {\n                // _value isn't used in script if specialValue == null\n                if (specialValue != null) {\n                    if (value instanceof Number) {\n                        specialValue.setValue(leaf, ((Number) value).doubleValue());","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionAggregationScript.java#L51-L87","documentation":"Thrown as GeneralScriptException by ExpressionAggregationScript.execute when calling doubleValue() on the bound DoubleValues raises any Exception during aggregation script execution. The original exception is wrapped as the cause; the message echoes the compiled Expression source text for context. This is a runtime evaluation failure, not a parse/compile error.","triggerScenarios":"Running an aggregation with a lang: expression script (scripted_metric, bucket_script, etc.) where evaluating the expression at query time throws - e.g. referencing a field that has no doc_values, a binding that returns no values for a doc, or arithmetic producing an invalid result.","commonSituations":"Referencing a text/keyword field (no numeric doc_values) in a numeric expression; field disabled for doc_values; expression divides by zero or references an unbound variable that yields no value; corrupted fielddata.","solutions":["Inspect the wrapped cause in the stack trace to find the real failure (missing doc_values, unbound variable, etc.).","Ensure every field referenced in the expression is numeric with doc_values enabled.","Test the expression against a single doc first; simplify to isolate the failing term."],"exampleFix":"// before: 'tags' is a keyword field with no doc_values for numeric use\n{\"script\": {\"source\": \"doc['price'].value + doc['tags'].value\", \"lang\": \"expression\"}}\n\n// after: reference only numeric doc-values fields\n{\"script\": {\"source\": \"doc['price'].value\", \"lang\": \"expression\"}}","handlingStrategy":"try-catch","validationCode":"// Before using a field in an aggregation expression, confirm it is numeric with doc_values\nGetMappingsResponse m = client.indices().getMappings(s -> s.index(idx)).result();\n// inspect the field type; ensure 'double','long', etc. and doc_values=true","typeGuard":null,"tryCatchPattern":"try {\n    // run aggregation with expression script\n} catch (GeneralScriptException e) {\n    // e.getCause() holds the real reason (missing doc_values, unbound var, ...)\n    log.warn(\"expression aggregation failed\", e.getCause());\n    throw e;\n}","preventionTips":["Reference only numeric, doc_values-enabled fields in expression scripts.","Read the wrapped cause to find the real failure quickly.","Test expression aggregations on a small doc set before production."],"tags":["elasticsearch","lang-expression","expression-script","aggregation","runtime"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}