elastic/elasticsearch · error · GeneralScriptException
Error evaluating {}
Error message
Error evaluating {} What it means
Thrown as GeneralScriptException by ExpressionFieldScript.execute when doubleValue() raises any Exception while evaluating a field-level expression script (runtime_field or script_fields). The compiled Expression source is included in the message and the original exception is the cause. This is the field-script counterpart of error 1214.
Source
Thrown at modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionFieldScript.java:43
ExpressionFieldScript(Expression e, SimpleBindings b) {
this.exprScript = e;
this.source = exprScript.getDoubleValuesSource(b);
}
@Override
public FieldScript newInstance(final LeafReaderContext leaf) throws IOException {
return new FieldScript() {
// Fake the scorer until setScorer is called.
DoubleValues values = source.getValues(leaf, null);
@Override
public Object execute() {
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
- Read the wrapped cause to find the specific failure (unbound variable, missing doc_values, etc.).
- Ensure referenced fields are numeric with doc_values enabled.
- For runtime fields on non-numeric data, switch to lang: painless.
Example fix
// before: script_fields references a keyword field
{"script_fields": {"calc": {"script": {"source": "doc['tags'].value * 2", "lang": "expression"}}}}
// after: reference a numeric field
{"script_fields": {"calc": {"script": {"source": "doc['price'].value * 2", "lang": "expression"}}}} Defensive patterns
Strategy: try-catch
Validate before calling
// Before using a field in a script_fields/runtime expression, confirm numeric doc_values GetMappingsResponse m = client.indices().getMappings(s -> s.index(idx)).result(); // ensure the referenced field is numeric with doc_values=true
Try / catch
try {
// script_fields / runtime field query with expression
} catch (GeneralScriptException e) {
// e.getCause() holds the real reason; log and surface to caller
log.warn("field expression failed", e.getCause());
throw e;
} Prevention
- Reference only numeric, doc_values-enabled fields in field-level expression scripts.
- Use painless for non-numeric or complex runtime field logic.
- Inspect the wrapped cause to pinpoint unbound variables or missing doc_values.
When it happens
Trigger: Using a lang: expression script in script_fields or as a runtime field where evaluating the expression per document throws - e.g. referencing a non-numeric field, a field without doc_values, or an unbound variable.
Common situations: Referencing a text/keyword field in a numeric expression; field with doc_values disabled; typo in field name producing an unbound variable; using an expression on a field type the engine can't read numerically.
Related errors
- Error evaluating {}
- Can't advance to doc using {}
- Member variable [{}] does not exist for date field [{}].
- Member method [{}] does not exist for date field [{}].
- Member variable [{}] does not exist for date object on field
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/a50466bf09c99be4.
Report an issue: GitHub.