{"record":{"id":"414871ce2518b1ac","repo":"SonarSource/sonarqube","slug":"fail-to-execute-es-request","errorCode":null,"errorMessage":"Fail to execute es request","messagePattern":"Fail to execute es request","errorType":"exception","errorClass":"ElasticsearchException","httpStatus":null,"severity":"error","filePath":"server/sonar-server-common/src/main/java/org/sonar/server/es/EsClient.java","lineNumber":357,"sourceCode":"        keyStore.load(is, keyStorePassword == null ? null : keyStorePassword.toCharArray());\n      }\n      SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(keyStore, null);\n      return sslBuilder.build();\n    } catch (IOException | GeneralSecurityException e) {\n      throw new IllegalStateException(\"Failed to setup SSL context on ES client\", e);\n    }\n  }\n\n  <R> R execute(EsRequestExecutor<R> executor) {\n    return execute(executor, () -> \"\");\n  }\n\n  <R> R execute(EsRequestExecutor<R> executor, Supplier<String> requestDetails) {\n    Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start();\n    try {\n      return executor.execute();\n    } catch (Exception e) {\n      throw new ElasticsearchException(\"Fail to execute es request\" + requestDetails.get(), e);\n    } finally {\n      if (profiler.isTraceEnabled()) {\n        profiler.stopTrace(requestDetails.get());\n      }\n    }\n  }\n\n  @FunctionalInterface\n  interface EsRequestExecutor<R> {\n    R execute() throws IOException;\n  }\n}\n","sourceCodeStart":339,"sourceCodeEnd":370,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-server-common/src/main/java/org/sonar/server/es/EsClient.java#L339-L370","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nesClient.prepareSearch(\"components\").setQuery(wrongQuery);\n// after: validate query against the index mapping first\n// GET /components/_mapping  then adjust field names/types in the query","handlingStrategy":"retry","validationCode":"// Preflight cluster health before requests:\n// curl -s http://es-host:9200/_cluster/health | jq .status  # expect green/yellow","typeGuard":null,"tryCatchPattern":"try {\n  return esClient.execute(executor, () -> \"search components\");\n} catch (ElasticsearchException e) {\n  if (e.getCause() instanceof ConnectException || e.getCause() instanceof SocketTimeoutException) {\n    return retryWithBackoff(executor, 3);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["elasticsearch","network","request"],"backgroundTag":"database-query-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}