SonarSource/sonarqube · error · ElasticsearchException
Fail to execute es request
Error message
Fail to execute es request
What it means
EsClient.execute wraps every Elasticsearch request through the REST client; any exception thrown by executor.execute() (IOException, connection refused, timeouts, index errors surfaced as ElasticsearchStatusException) is rethrown as an ElasticsearchException prefixed with "Fail to execute es request" plus request details from the supplier, preserving the cause.
Source
Thrown at server/sonar-server-common/src/main/java/org/sonar/server/es/EsClient.java:357
keyStore.load(is, keyStorePassword == null ? null : keyStorePassword.toCharArray());
}
SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(keyStore, null);
return sslBuilder.build();
} catch (IOException | GeneralSecurityException e) {
throw new IllegalStateException("Failed to setup SSL context on ES client", e);
}
}
<R> R execute(EsRequestExecutor<R> executor) {
return execute(executor, () -> "");
}
<R> R execute(EsRequestExecutor<R> executor, Supplier<String> requestDetails) {
Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start();
try {
return executor.execute();
} catch (Exception e) {
throw new ElasticsearchException("Fail to execute es request" + requestDetails.get(), e);
} finally {
if (profiler.isTraceEnabled()) {
profiler.stopTrace(requestDetails.get());
}
}
}
@FunctionalInterface
interface EsRequestExecutor<R> {
R execute() throws IOException;
}
}
View on GitHub (pinned to 184c821202)
Solutions
- Read the wrapped cause and the appended request details to identify the underlying ES failure.
- Check cluster health (`GET _cluster/health`) and that SonarQube can reach the ES host/port.
- Verify client and server Elasticsearch versions are compatible.
- Check disk watermarks and index read-only blocks if writes fail.
- Fix or regenerate the query/mapping if the cause indicates a parse/mapping error.
Example fix
// before
esClient.prepareSearch("components").setQuery(wrongQuery);
// after: validate query against the index mapping first
// GET /components/_mapping then adjust field names/types in the query Defensive patterns
Strategy: retry
Validate before calling
// Preflight cluster health before requests: // curl -s http://es-host:9200/_cluster/health | jq .status # expect green/yellow
Try / catch
try {
return esClient.execute(executor, () -> "search components");
} catch (ElasticsearchException e) {
if (e.getCause() instanceof ConnectException || e.getCause() instanceof SocketTimeoutException) {
return retryWithBackoff(executor, 3);
}
throw e;
} Prevention
- Monitor ES cluster health and disk watermarks.
- Keep SonarQube and Elasticsearch versions compatible.
- Use request details suppliers to make failures diagnosable.
- Retry idempotent read requests with exponential backoff.
When it happens
Trigger: Any ES-backed operation (search, indexing, deleteByQuery) when the cluster is unreachable, the node is red, a mapping/query is invalid, the index is missing, or a timeout occurs.
Common situations: Elasticsearch down or restarting; version incompatibility between client and cluster; malformed queries after upgrade; disk watermark exceeded making the index read-only; network/firewall blocks between SonarQube and ES nodes.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- Can not resolve host [
- Can not resolve host [. Please check network settings and pr
- Can not resolve host [
- SonarQube was not able to retrieve resources from external s
- %s for request [%s]: [%s]
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/414871ce2518b1ac.
Report an issue: GitHub.