{"record":{"id":"1658bcf2bc3a5cb9","repo":"elastic/elasticsearch","slug":"can-t-advance-to-doc-using-1658bc","errorCode":null,"errorMessage":"Can't advance to doc using {}","messagePattern":"Can't advance to doc using (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionTermSetQueryScript.java","lineNumber":59,"sourceCode":"        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":41,"sourceCodeEnd":66,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionTermSetQueryScript.java#L41-L66","documentation":"Thrown inside ExpressionTermSetQueryScript.setDocument(d) when values.advanceExact(d) raises IOException, wrapped in IllegalStateException with the expression source text. This is the terms-set-query counterpart of errors 1220/1222/1224 — the Lucene DoubleValues cursor cannot be positioned at the target document.","triggerScenarios":"Executing a terms_set query with an expression script; advanceExact fails due to an I/O error reading segment data for document d. Distinct from 1238 which fires during value retrieval.","commonSituations":"Segment corruption; reader closed mid-query (refresh or merge during search); disk I/O errors; concurrent shard relocation causing reader invalidation.","solutions":["Check cluster and shard health: GET _cluster/health?level=shards.","Inspect segments for corruption: GET <index>/_segments.","Refresh the index to get a fresh reader: POST <index>/_refresh.","Restore from snapshot if segment corruption is confirmed."],"exampleFix":"// No code fix — runtime I/O failure during terms_set query evaluation.\n// Diagnose shard/segment health:\nGET _cluster/health?level=shards\nGET my-index/_segments\n// Restore if corrupt:\nPOST _snapshot/my_backup/snap_1/_restore\n{\"indices\": \"my-index\"}","handlingStrategy":"try-catch","validationCode":"// Before running a terms_set query, verify shard health\nGET _cluster/health/<index>?level=shards","typeGuard":null,"tryCatchPattern":"try {\n    termsSetScript.setDocument(docId);\n} catch (IllegalStateException e) {\n    logger.error(\"Terms set expression advanceExact failed for doc [{}]: {}\", docId, e.getMessage(), e);\n    // I/O-level failure — typically fail the shard request\n    throw e;\n}","preventionTips":["Monitor disk I/O and segment health on data nodes.","Avoid running force_merge or shard relocation concurrently with terms_set queries.","Keep snapshots current for fast recovery from segment corruption.","Run GET <index>/_segments to detect anomalies before they cause query failures."],"tags":["expression","script","terms-set-query","io","lucene"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}