{"record":{"id":"d1b5bf75f64452ed","repo":"xkcoding/spring-boot-demo","slug":"index-id-id","errorCode":null,"errorMessage":"删除索引 {index} 数据id {id} 失败","messagePattern":"删除索引 (.+?) 数据id (.+?) 失败","errorType":"exception","errorClass":"ElasticsearchException","httpStatus":null,"severity":"error","filePath":"demo-elasticsearch-rest-high-level-client/src/main/java/com/xkcoding/elasticsearch/service/base/BaseElasticsearchService.java","lineNumber":140,"sourceCode":"            client.update(updateRequest, COMMON_OPTIONS);\n        } catch (IOException e) {\n            throw new ElasticsearchException(\"更新索引 {\" + index + \"} 数据 {\" + object + \"} 失败\");\n        }\n    }\n\n    /**\n     * exec deleteRequest\n     *\n     * @param index elasticsearch index name\n     * @param id    Document id\n     * @author fxbin\n     */\n    protected void deleteRequest(String index, String id) {\n        try {\n            DeleteRequest deleteRequest = new DeleteRequest(index, id);\n            client.delete(deleteRequest, COMMON_OPTIONS);\n        } catch (IOException e) {\n            throw new ElasticsearchException(\"删除索引 {\" + index + \"} 数据id {\" + id + \"} 失败\");\n        }\n    }\n\n    /**\n     * search all\n     *\n     * @param index elasticsearch index name\n     * @return {@link SearchResponse}\n     * @author fxbin\n     */\n    protected SearchResponse search(String index) {\n        SearchRequest searchRequest = new SearchRequest(index);\n        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();\n        searchSourceBuilder.query(QueryBuilders.matchAllQuery());\n        searchRequest.source(searchSourceBuilder);\n        SearchResponse searchResponse = null;\n        try {\n            searchResponse = client.search(searchRequest, COMMON_OPTIONS);","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/xkcoding/spring-boot-demo/blob/87a142f9604c1a5365b4d24d22c2c11c26a9d5ab/demo-elasticsearch-rest-high-level-client/src/main/java/com/xkcoding/elasticsearch/service/base/BaseElasticsearchService.java#L122-L158","documentation":"Thrown by deleteRequest when client.delete() raises an IOException during deletion of a single document by id. Only IOException is caught; if the document or index does not exist, the RestHighLevelClient throws a RuntimeException (ElasticsearchStatusException) which bypasses this handler. The original cause is discarded.","triggerScenarios":"Calling deleteRequest(index, id) when: the cluster is unreachable (IOException); the document id does not exist (RuntimeException, not caught here); the index does not exist (RuntimeException).","commonSituations":"Deleting a document that was already removed; cluster offline during a cleanup operation; network timeout; attempting deletion against a read-only index.","solutions":["Verify cluster connectivity and index existence before calling deleteRequest.","Chain the cause: new ElasticsearchException(\"...\", e) for diagnostic visibility.","Add a catch for ElasticsearchStatusException to handle 'not found' gracefully if idempotent deletes are desired.","Ensure the document id is non-null and correctly formatted."],"exampleFix":"// before\n} catch (IOException e) {\n    throw new ElasticsearchException(\"删除索引 {\" + index + \"} 数据id {\" + id + \"} 失败\");\n}\n\n// after\n} catch (IOException e) {\n    throw new ElasticsearchException(\"删除索引 {\" + index + \"} 数据id {\" + id + \"} 失败\", e);\n}","handlingStrategy":"validation","validationCode":"// Verify document exists before delete (optional, for idempotency)\nGetRequest getRequest = new GetRequest(index, id);\ntry {\n    if (!client.exists(getRequest, COMMON_OPTIONS)) {\n        log.warn(\"Document {} not found in index {}, skipping delete\", id, index);\n        return;\n    }\n} catch (IOException e) {\n    log.error(\"Cannot verify document existence\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    deleteRequest(index, id);\n} catch (ElasticsearchException e) {\n    log.error(\"Delete failed for index={}, id={}: {}\", index, id, e.getMessage());\n    throw e;\n}","preventionTips":["Validate the id is non-null and non-empty before calling deleteRequest.","Treat 'not found' as success if idempotent deletes are desired.","Chain the IOException cause for debugging."],"tags":["elasticsearch","network","io-exception","rest-high-level-client","configuration"],"backgroundTag":null,"analyzedSha":"87a142f9604c1a5365b4d24d22c2c11c26a9d5ab","analyzedAt":"2026-08-14T01:16:58.217Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}