{"record":{"id":"fc4c5a7dda7c64e8","repo":"alibaba/spring-ai-alibaba","slug":"error","errorCode":null,"errorMessage":"搜索请求执行失败","messagePattern":"搜索请求执行失败","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/ElasticsearchClientWrapper.java","lineNumber":32,"sourceCode":"import java.util.List;\nimport java.util.Map;\nimport java.util.stream.Collectors;\n\n@Component\n@RequiredArgsConstructor\n@Slf4j\npublic class ElasticsearchClientWrapper {\n\n    private final ElasticsearchClient elasticsearchClient;\n\n    /**\n     * 执行搜索查询\n     */\n    public SearchResponse<Map> search(String index, SearchRequest searchRequest) {\n        try {\n            return elasticsearchClient.search(searchRequest, Map.class);\n        } catch (IOException e) {\n            throw new RuntimeException(\"搜索请求执行失败\", e);\n        }\n    }\n\n    /**\n     * 批量索引文档\n     */\n    public void bulkIndex(String index, List<Map<String, Object>> documents) {\n        try {\n            BulkRequest.Builder bulkBuilder = new BulkRequest.Builder();\n            \n            for (Map<String, Object> doc : documents) {\n                bulkBuilder.operations(op -> op\n                    .index(idx -> idx\n                        .index(index)\n                        .document(doc)\n                    )\n                );\n            }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/ElasticsearchClientWrapper.java#L14-L50","documentation":"ElasticsearchClientWrapper.search() delegates to elasticsearchClient.search() and wraps any IOException in a RuntimeException \"搜索请求执行失败\" (\"Search request execution failed\"). IOExceptions here indicate the request could not reach the cluster or the connection broke mid-request — not query-syntax problems, which surface as Elasticsearch API errors instead.","triggerScenarios":"Calling search(index, searchRequest) when the Elasticsearch node is down, the connection is refused/timed out, the socket is reset, or DNS resolution fails while executing the search request.","commonSituations":"ES cluster restart during a request; network partition or firewall dropping port 9200; connection-pool exhaustion from a load spike; stale keep-alive connections after idle periods.","solutions":["Inspect the wrapped IOException cause (ConnectException, SocketTimeoutException, etc.) to identify the network problem.","Verify the ES cluster is up and reachable from the app host (curl http://host:9200/_cluster/health).","Check for connection-pool saturation and tune maxConnTotal/maxConnPerRoute.","Add retry logic with backoff for transient IO failures, or use the low-level RestClient's built-in failure listener/retry.","Ensure keep-alive/idle connection settings match the LB/firewall timeout."],"exampleFix":"// before\ncatch (IOException e) { throw new RuntimeException(\"搜索请求执行失败\", e); }\n// after\ncatch (IOException e) {\n    if (e instanceof java.net.ConnectException) { /* mark node unhealthy, retry other node */ }\n    throw new RuntimeException(\"搜索请求执行失败: \" + e.getMessage(), e);\n}","handlingStrategy":"retry","validationCode":"// before querying\ntry (var sock = new Socket()) { sock.connect(new InetSocketAddress(host, 9200), 2000); }","typeGuard":null,"tryCatchPattern":"try { return wrapper.search(index, req); }\ncatch (RuntimeException e) {\n    Throwable c = e.getCause();\n    if (c instanceof IOException && isTransient(c)) { return retryWithBackoff(() -> wrapper.search(index, req), 3); }\n    throw e;\n}","preventionTips":["Monitor cluster health and alert before saturation","Configure the low-level RestClient's node-sniffing/failure listener for failover","Tune keep-alive on connections to survive LB idle timeouts","Use bounded retries with exponential backoff for idempotent searches"],"tags":["elasticsearch","io","network","search","java"],"backgroundTag":"http-request-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}