elastic/elasticsearch · error · GeneralScriptException
Error evaluating {}
Error message
Error evaluating {} What it means
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.
Source
Thrown at modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScoreScript.java:81
// Fake the scorer until setScorer is called.
DoubleValues values = source.getValues(leaf, new DoubleValues() {
@Override
public double doubleValue() throws IOException {
return get_score();
}
@Override
public boolean advanceExact(int doc) throws IOException {
return true;
}
});
@Override
public double execute(ExplanationHolder explanation) {
try {
return values.doubleValue();
} catch (Exception exception) {
throw new GeneralScriptException("Error evaluating " + exprScript, exception);
}
}
@Override
public void setDocument(int d) {
try {
values.advanceExact(d);
} catch (IOException e) {
throw new IllegalStateException("Can't advance to doc using " + exprScript, e);
}
}
};
}
}
View on GitHub (pinned to db6a809a66)
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.
Example fix
// before: expression references field that may be missing
GET my-index/_search
{
"query": {
"function_score": {
"script_score": { "script": { "lang": "expression", "source": "doc['rating'].value" } }
}
}
}
// after: ensure field has doc_values and provide default via params
GET my-index/_search
{
"query": {
"function_score": {
"script_score": {
"script": {
"lang": "expression",
"source": "doc['rating'].value",
"params": {}
}
}
}
}
} Defensive patterns
Strategy: try-catch
Validate before calling
// Before using a script_score query, verify the expression's fields exist and have data
GET my-index/_search
{ "size": 0, "aggs": { "check": { "stats": { "field": "rating" } } } }
// If 'rating' returns no stats, the expression will fail at runtime Try / catch
try {
double score = scoreScript.execute(explanationHolder);
} catch (GeneralScriptException e) {
logger.warn("Expression score evaluation failed: {}", e.getMessage(), e);
// Return a neutral score or rethrow depending on query requirements
return 1.0f;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error evaluating {}
- Can't advance to doc using {}
- Error evaluating {}
- Can't advance to doc using {}
- Can't advance to doc using {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/d092b7e8a4c7c405.
Report an issue: GitHub.