{"record":{"id":"1cfcf584fd4add74","repo":"prestodb/presto","slug":"elasticsearch-query-failure","errorCode":"ELASTICSEARCH_QUERY_FAILURE","errorMessage":"ELASTICSEARCH_QUERY_FAILURE","messagePattern":"ELASTICSEARCH_QUERY_FAILURE","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/client/ElasticsearchClient.java","lineNumber":786,"sourceCode":"        if (entity != null && entity.getContentType() != null) {\n            try {\n                JsonNode reason = OBJECT_MAPPER.readTree(entity.getContent()).path(\"error\")\n                        .path(\"root_cause\")\n                        .path(0)\n                        .path(\"reason\");\n\n                if (!reason.isMissingNode()) {\n                    throw new PrestoException(ELASTICSEARCH_QUERY_FAILURE, reason.asText(), exception);\n                }\n            }\n            catch (IOException e) {\n                PrestoException result = new PrestoException(ELASTICSEARCH_QUERY_FAILURE, exception);\n                result.addSuppressed(e);\n                throw result;\n            }\n        }\n\n        throw new PrestoException(ELASTICSEARCH_QUERY_FAILURE, exception);\n    }\n\n    @VisibleForTesting\n    static Optional<String> extractAddress(String address)\n    {\n        Matcher matcher = ADDRESS_PATTERN.matcher(address);\n\n        if (!matcher.matches()) {\n            return Optional.empty();\n        }\n\n        String cname = matcher.group(\"cname\");\n        String ip = matcher.group(\"ip\");\n        String port = matcher.group(\"port\");\n\n        if (cname != null) {\n            return Optional.of(cname + \":\" + port);\n        }","sourceCodeStart":768,"sourceCodeEnd":804,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/client/ElasticsearchClient.java#L768-L804","documentation":"When the Elasticsearch client executes a search and the response contains failed shards with a root_cause failure reason, the connector surfaces it as a PrestoException with code ELASTICSEARCH_QUERY_FAILURE. The underlying exception (often ElasticsearchStatusException) is attached, and any earlier error encountered while parsing the failure is added as suppressed.","triggerScenarios":"A search request fails server-side: shard exceptions from malformed queries (e.g. bad query_string syntax), field mapped inconsistently across shards, script errors, or too_many_clauses/limit violations returned in the response's _shards.failures.","commonSituations":"Pushed-down predicates referencing fields whose mapping differs between indices under an alias; regex/syntax errors in LIKE or query_string pushdown; ES node overload causing shard failures; index corruption.","solutions":["Read the cause (ElasticsearchStatusException / root_cause) to see the real server-side reason.","Fix the query predicate that Elasticsearch rejects (check syntax of pushed-down LIKE/regex/filters).","Reindex or fix mappings so aliased indices have consistent field types.","Check cluster health and shard allocation (GET _cat/shards) for failed/unavailable shards."],"exampleFix":"// before: predicate causing shard failure\nWHERE nested_field.value = 'x' -- field mapped differently across shards\n// after: align mapping or cast\nreindex conflicting indices with a consistent mapping, then rerun","handlingStrategy":"try-catch","validationCode":"// check cluster and shard health first\ncurl -s 'localhost:9200/_cat/shards?v&h=index,shard,state'\ncurl -s 'localhost:9200/_cluster/health?filter_path=status,unassigned_shards'","typeGuard":null,"tryCatchPattern":"try {\n    runQuery(pushdownQuery);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"ELASTICSEARCH_QUERY_FAILURE\") && e.getCause() != null) {\n        // inspect e.getCause() (ElasticsearchStatusException) root_cause for the real reason\n    } else { throw e; }\n}","preventionTips":["Keep field mappings consistent across all indices an alias spans.","Test pushed-down predicates (LIKE/regex/filters) directly against ES before Presto queries.","Monitor cluster health and failed-shard metrics.","Read root_cause in ES responses to fix queries at the source."],"tags":["elasticsearch","query-failure","shard-failure","server-error"],"backgroundTag":"elasticsearch-query-failure","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}