{"record":{"id":"d092b7e8a4c7c405","repo":"elastic/elasticsearch","slug":"error-evaluating-d092b7","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/ExpressionScoreScript.java","lineNumber":81,"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();\n                }\n\n                @Override\n                public boolean advanceExact(int doc) throws IOException {\n                    return true;\n                }\n            });\n\n            @Override\n            public double execute(ExplanationHolder explanation) {\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    }\n\n}\n","sourceCodeStart":63,"sourceCodeEnd":97,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScoreScript.java#L63-L97","documentation":"Thrown inside ExpressionScoreScript.execute(ExplanationHolder) when values.doubleValue() raises any Exception, wrapped in GeneralScriptException with the expression source text. This fires during function_score or script_score evaluation when the computed score cannot be retrieved for the current document.","triggerScenarios":"Using a function_score or script_score query with \"lang\":\"expression\" and doubleValue() fails — e.g., the backing DoubleValues (often _score or a doc value) is unavailable or raises an error during score computation.","commonSituations":"Expression references _score when the query does not actually produce scores; doc_values field is missing for some documents; expression causes arithmetic overflow or references an unloaded field data cache.","solutions":["If the expression uses _score, ensure the surrounding query is a score-producing query (not a filter context).","Verify all doc['field'] references point to fields with doc_values enabled and present in the mapping.","Simplify the expression to isolate which variable causes the failure: start with doc['field'].value, then add complexity.","Provide a fallback by wrapping the script in a condition or using the script's params to supply defaults for missing values."],"exampleFix":"// before: expression references field that may be missing\nGET my-index/_search\n{\n  \"query\": {\n    \"function_score\": {\n      \"script_score\": { \"script\": { \"lang\": \"expression\", \"source\": \"doc['rating'].value\" } }\n    }\n  }\n}\n// after: ensure field has doc_values and provide default via params\nGET my-index/_search\n{\n  \"query\": {\n    \"function_score\": {\n      \"script_score\": {\n        \"script\": {\n          \"lang\": \"expression\",\n          \"source\": \"doc['rating'].value\",\n          \"params\": {}\n        }\n      }\n    }\n  }\n}","handlingStrategy":"try-catch","validationCode":"// Before using a script_score query, verify the expression's fields exist and have data\nGET my-index/_search\n{ \"size\": 0, \"aggs\": { \"check\": { \"stats\": { \"field\": \"rating\" } } } }\n// If 'rating' returns no stats, the expression will fail at runtime","typeGuard":null,"tryCatchPattern":"try {\n    double score = scoreScript.execute(explanationHolder);\n} catch (GeneralScriptException e) {\n    logger.warn(\"Expression score evaluation failed: {}\", e.getMessage(), e);\n    // Return a neutral score or rethrow depending on query requirements\n    return 1.0f;\n}","preventionTips":["Ensure all doc['field'] references in score expressions are numeric/date/geo fields with doc_values.","If the expression uses _score, confirm the query runs in score context (not filter context).","Test the expression against documents known to have the referenced fields.","Avoid referencing fields that may be absent for some documents without a fallback strategy."],"tags":["expression","script","score","function-score","doc-values"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}