{"record":{"id":"0a54e0cdc487efae","repo":"elastic/elasticsearch","slug":"error-evaluating-0a54e0","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/ExpressionNumberSortScript.java","lineNumber":72,"sourceCode":"            // Fake the scorer until setScorer is called.\n            DoubleValues values = source.getValues(ctx, new DoubleValues() {\n                @Override\n                public double doubleValue() {\n                    return 0.0D;\n                }\n\n                @Override\n                public boolean advanceExact(int doc) {\n                    return true;\n                }\n            });\n\n            @Override\n            public double 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    }\n\n    @Override\n    public boolean needs_score() {\n        return needsScores;\n    }","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionNumberSortScript.java#L54-L90","documentation":"Thrown inside ExpressionNumberSortScript.execute() when values.doubleValue() raises any Exception. The expression engine catches it and wraps it in a GeneralScriptException that includes the compiled expression source text. doubleValue() is called after advanceExact, so this represents a failure computing or retrieving the numeric result for the current document.","triggerScenarios":"Sorting by an expression script (\"sort\": {\"_script\": {\"type\": \"number\", \"script\": {\"lang\": \"expression\", \"source\": \"doc['price'].value * 1.2\"}}}) and doubleValue() fails — e.g., the DoubleValues source returned false from advanceExact internally, or a backing doc-values lookup threw.","commonSituations":"Referencing a field that has doc_values disabled; sorting on a field that is multi-valued when the expression expects a single value; expression produces a value that overflows or is otherwise invalid for the sort path.","solutions":["Verify every field referenced in the expression has doc_values enabled (default true for numeric/date — check mapping for \"doc_values\": false).","Confirm the field exists and has data for the documents being sorted; use the missing sort option to supply a default for documents without the field.","Test the expression against a single document with GET <index>/_search?q=_id:<docId> to isolate which document triggers the failure.","If the field is multi-valued, use a specific accessor method (e.g., doc['field'].value returns the first value) or pre-process the data."],"exampleFix":"// before: field may have doc_values disabled\nPUT my-index/_mapping\n{ \"properties\": { \"price\": { \"type\": \"double\", \"doc_values\": false } } }\n// sort expression fails at runtime\n// after: enable doc_values (requires reindex)\nPUT my-index-new/_mapping\n{ \"properties\": { \"price\": { \"type\": \"double\" } } }\nPOST _reindex { \"source\": {\"index\":\"my-index\"}, \"dest\": {\"index\":\"my-index-new\"} }","handlingStrategy":"validation","validationCode":"// Before using an expression sort, verify all referenced fields have doc_values enabled\nGET my-index/_mapping\n// In application code, validate the mapping before building the sort:\n// Check that each doc['field'] in the expression is a numeric/date/geo field with doc_values: true","typeGuard":null,"tryCatchPattern":"// When calling a sort script programmatically:\ntry {\n    double sortValue = sortScript.execute();\n} catch (GeneralScriptException e) {\n    logger.warn(\"Expression sort evaluation failed for expression [{}]\", exprSource, e);\n    // Return a neutral sort value or skip the document\n    return 0.0;\n}","preventionTips":["Always verify field mappings have doc_values enabled before using them in expression sorts.","Use the 'missing' sort parameter to provide a default for documents without the field.","Test expressions on a small document subset before deploying to production queries.","Avoid expressions that could produce NaN or Infinity (e.g., division by zero)."],"tags":["expression","script","sort","doc-values","runtime"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}