{"record":{"id":"686d082bf04e49f4","repo":"alibaba/spring-ai-alibaba","slug":"error-686d08","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":61,"sourceCode":"            for (Map<String, Object> doc : documents) {\n                bulkBuilder.operations(op -> op\n                    .index(idx -> idx\n                        .index(index)\n                        .document(doc)\n                    )\n                );\n            }\n            \n            BulkResponse result = elasticsearchClient.bulk(bulkBuilder.build());\n            \n            if (result.errors()) {\n                log.error(\"批量索引部分失败: {}\", result.items());\n            } else {\n                log.info(\"批量索引成功: {} 条文档\", documents.size());\n            }\n            \n        } catch (IOException e) {\n            throw new RuntimeException(\"批量索引失败\", e);\n        }\n    }\n\n    /**\n     * 检查索引是否存在\n     */\n    public boolean indexExists(String indexName) {\n        try {\n            ExistsRequest existsRequest = ExistsRequest.of(e -> e.index(indexName));\n            return elasticsearchClient.indices().exists(existsRequest).value();\n        } catch (IOException e) {\n            log.error(\"检查索引是否存在失败: {}\", indexName, e);\n            return false;\n        }\n    }\n\n    /**\n     * 转换SearchResponse到Map列表","sourceCodeStart":43,"sourceCodeEnd":79,"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#L43-L79","documentation":"ElasticsearchClientWrapper.bulkIndex() performs a BulkRequest and wraps any IOException in a RuntimeException \"批量索引失败\" (\"Bulk indexing failed\"). This signals a transport-level failure to send the bulk request or read the response; partial per-item failures inside a successful response are only logged, not thrown.","triggerScenarios":"Calling bulkIndex() with documents when the ES connection drops mid-request, the request times out on large payloads, or the node is unreachable while executing client.bulk().","commonSituations":"Bulk-loading a large dataset during a network hiccup; ES node restart mid-write; request payload exceeding http.max_content_length; timeout from slow indexing under load.","solutions":["Check the wrapped IOException cause for the real network/timeout error.","Verify cluster health and that the node is reachable during the bulk operation.","Reduce bulk batch size or split large payloads to stay under http.max_content_length.","Increase request timeouts and add retry-with-backoff around bulkIndex.","Note the code only throws on IOException — also inspect result.items() logs for per-document failures."],"exampleFix":"// before\ncatch (IOException e) { throw new RuntimeException(\"批量索引失败\", e); }\n// after\ncatch (IOException e) { throw new RuntimeException(\"批量索引失败: \" + e.getMessage(), e); } // plus retry wrapper for transient failures","handlingStrategy":"retry","validationCode":"// keep batches under limits\nif (documents.size() > 1000) { throw new IllegalArgumentException(\"batch too large, split it\"); }","typeGuard":null,"tryCatchPattern":"try { wrapper.bulkIndex(index, docs); }\ncatch (RuntimeException e) {\n    if (e.getCause() instanceof IOException && attempt < MAX) { backoff(); retry(docs); }\n    else throw e;\n}","preventionTips":["Use small bulk batches (500–1000 docs) instead of giant payloads","Verify es http.max_content_length accommodates your batch size","Track per-item failures from result.items(), not just the thrown exception","Schedule bulk loads away from cluster maintenance windows"],"tags":["elasticsearch","io","bulk","network","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"}