{"record":{"id":"3cfa7cd522d9edcf","repo":"elastic/elasticsearch","slug":"error-evaluating-3cfa7c","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/ExpressionTermSetQueryScript.java","lineNumber":50,"sourceCode":"\n    ExpressionTermSetQueryScript(Expression e, SimpleBindings b) {\n        exprScript = e;\n        bindings = b;\n        source = exprScript.getDoubleValuesSource(bindings);\n    }\n\n    @Override\n    public TermsSetQueryScript newInstance(final LeafReaderContext leaf) throws IOException {\n        return new TermsSetQueryScript() {\n            // Fake the scorer until setScorer is called.\n            DoubleValues values = source.getValues(leaf, null);\n\n            @Override\n            public Number 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}\n","sourceCodeStart":32,"sourceCodeEnd":66,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionTermSetQueryScript.java#L32-L66","documentation":"Thrown inside ExpressionTermSetQueryScript.execute() when values.doubleValue() raises any Exception, wrapped in GeneralScriptException with the expression source text. This fires during terms_set query evaluation when the computed numeric result for a document cannot be retrieved.","triggerScenarios":"Using a terms_set query with \"minimum_should_match_field\" or \"minimum_should_match_script\" using \"lang\":\"expression\", and doubleValue() fails during evaluation — e.g., the referenced field has no value for the document or the doc-values source encounters an error.","commonSituations":"Field referenced in the terms_set expression has doc_values disabled or is missing for some documents; expression produces an invalid value; corrupted field data for the specific segment.","solutions":["Verify the field used in the terms_set expression has doc_values enabled and exists in the mapping.","Ensure the field has values for the documents being queried — check with a simple term or exists query first.","Test the expression independently with a function_score or sort to isolate whether it's specific to the terms_set path.","If only some documents are affected, provide a default value via params or use a conditional in Painless."],"exampleFix":"// before: field may be missing or non-numeric\nGET my-index/_search\n{\n  \"query\": {\n    \"terms_set\": {\n      \"tags\": {\n        \"terms\": [\"elasticsearch\", \"search\"],\n        \"minimum_should_match_script\": {\n          \"lang\": \"expression\",\n          \"source\": \"doc['required_matches'].value\"\n        }\n      }\n    }\n  }\n}\n// after: verify field exists with GET my-index/_mapping, ensure doc_values enabled\n// If field is optional, use Painless with a null check instead.","handlingStrategy":"try-catch","validationCode":"// Before using a terms_set expression, verify the referenced field has data\nGET my-index/_search\n{ \"size\": 0, \"aggs\": { \"check\": { \"stats\": { \"field\": \"required_matches\" } } } }\n// If no stats are returned, the field is empty or missing and the expression will fail","typeGuard":null,"tryCatchPattern":"try {\n    Number result = termsSetScript.execute();\n} catch (GeneralScriptException e) {\n    logger.warn(\"Terms set expression evaluation failed: {}\", e.getMessage(), e);\n    // Return a default that means 'no match' or rethrow depending on requirements\n    return 0;\n}","preventionTips":["Ensure the field referenced in the terms_set expression has doc_values enabled and contains data.","Test the expression on documents known to have values for all referenced fields.","Provide default values via params for fields that may be absent.","Validate field data availability with a simple stats aggregation before deploying the terms_set query."],"tags":["expression","script","terms-set-query","doc-values","runtime"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}