prestodb/presto · error · PrestoException
ELASTICSEARCH_QUERY_FAILURE
ELASTICSEARCH_QUERY_FAILURE
Error message
ELASTICSEARCH_QUERY_FAILURE
What it means
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.
Source
Thrown at presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/client/ElasticsearchClient.java:786
if (entity != null && entity.getContentType() != null) {
try {
JsonNode reason = OBJECT_MAPPER.readTree(entity.getContent()).path("error")
.path("root_cause")
.path(0)
.path("reason");
if (!reason.isMissingNode()) {
throw new PrestoException(ELASTICSEARCH_QUERY_FAILURE, reason.asText(), exception);
}
}
catch (IOException e) {
PrestoException result = new PrestoException(ELASTICSEARCH_QUERY_FAILURE, exception);
result.addSuppressed(e);
throw result;
}
}
throw new PrestoException(ELASTICSEARCH_QUERY_FAILURE, exception);
}
@VisibleForTesting
static Optional<String> extractAddress(String address)
{
Matcher matcher = ADDRESS_PATTERN.matcher(address);
if (!matcher.matches()) {
return Optional.empty();
}
String cname = matcher.group("cname");
String ip = matcher.group("ip");
String port = matcher.group("port");
if (cname != null) {
return Optional.of(cname + ":" + port);
}View on GitHub (pinned to 55bb57d202)
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.
Example fix
// before: predicate causing shard failure WHERE nested_field.value = 'x' -- field mapped differently across shards // after: align mapping or cast reindex conflicting indices with a consistent mapping, then rerun
Defensive patterns
Strategy: try-catch
Validate before calling
// check cluster and shard health first curl -s 'localhost:9200/_cat/shards?v&h=index,shard,state' curl -s 'localhost:9200/_cluster/health?filter_path=status,unassigned_shards'
Try / catch
try {
runQuery(pushdownQuery);
} catch (PrestoException e) {
if (e.getErrorCode().getName().equals("ELASTICSEARCH_QUERY_FAILURE") && e.getCause() != null) {
// inspect e.getCause() (ElasticsearchStatusException) root_cause for the real reason
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Type not supported:
- Unexpected default trust managers:
- KeyStore certificate is expired:
- KeyStore certificate is not yet valid:
- ELASTICSEARCH_INVALID_RESPONSE
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/1cfcf584fd4add74.
Report an issue: GitHub.