{"record":{"id":"bd03b653300e37a1","repo":"xkcoding/spring-boot-demo","slug":"index-bd03b6","errorCode":null,"errorMessage":"删除索引 {index} 失败","messagePattern":"删除索引 (.+?) 失败","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":84,"sourceCode":"            log.info(\" whether all of the nodes have acknowledged the request : {}\", createIndexResponse.isAcknowledged());\n            log.info(\" Indicates whether the requisite number of shard copies were started for each shard in the index before timing out :{}\", createIndexResponse.isShardsAcknowledged());\n        } catch (IOException e) {\n            throw new ElasticsearchException(\"创建索引 {\" + index + \"} 失败\");\n        }\n    }\n\n    /**\n     * delete elasticsearch index\n     *\n     * @param index elasticsearch index name\n     * @author fxbin\n     */\n    protected void deleteIndexRequest(String index) {\n        DeleteIndexRequest deleteIndexRequest = buildDeleteIndexRequest(index);\n        try {\n            client.indices().delete(deleteIndexRequest, COMMON_OPTIONS);\n        } catch (IOException e) {\n            throw new ElasticsearchException(\"删除索引 {\" + index + \"} 失败\");\n        }\n    }\n\n    /**\n     * build DeleteIndexRequest\n     *\n     * @param index elasticsearch index name\n     * @author fxbin\n     */\n    private static DeleteIndexRequest buildDeleteIndexRequest(String index) {\n        return new DeleteIndexRequest(index);\n    }\n\n    /**\n     * build IndexRequest\n     *\n     * @param index  elasticsearch index name\n     * @param id     request object id","sourceCodeStart":66,"sourceCodeEnd":102,"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#L66-L102","documentation":"Thrown by deleteIndexRequest when client.indices().delete() raises an IOException during the HTTP call to delete an index from the Elasticsearch cluster. As with createIndexRequest, only IOException is caught; ES-level errors (index not found) surface as RuntimeExceptions and bypass this handler. The original cause is also discarded.","triggerScenarios":"Calling deleteIndexRequest on an index that does not exist while the cluster is reachable (produces a RuntimeException, not IOException — will not be caught here). IOException variant triggers on transport failures: cluster down, network timeout, or connection refused.","commonSituations":"Cluster offline during cleanup/shutdown; network instability between app and ES nodes; attempting to delete an already-deleted index during test teardown; wrong clusterNodes configuration.","solutions":["Confirm the ES cluster is running and reachable from the application host.","Check that the index name passed is valid and exists before calling delete (use IndicesClient.exists() first).","Pass the IOException as cause: new ElasticsearchException(\"...\", e) to preserve diagnostics.","Add a catch for ElasticsearchStatusException to handle the 'index not found' case without crashing."],"exampleFix":"// before\n} catch (IOException e) {\n    throw new ElasticsearchException(\"删除索引 {\" + index + \"} 失败\");\n}\n\n// after\n} catch (IOException e) {\n    throw new ElasticsearchException(\"删除索引 {\" + index + \"} 失败\", e);\n}","handlingStrategy":"validation","validationCode":"// Check index existence before deleting\ntry {\n    org.elasticsearch.client.indices.GetIndexRequest existsReq =\n        new org.elasticsearch.client.indices.GetIndexRequest(index);\n    if (!client.indices().exists(existsReq, COMMON_OPTIONS)) {\n        log.warn(\"Index {} does not exist, skipping delete\", index);\n        return;\n    }\n} catch (IOException e) {\n    log.error(\"Cannot verify index existence\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    deleteIndexRequest(index);\n} catch (ElasticsearchException e) {\n    log.error(\"Index deletion failed for {}: {}\", index, e.getMessage());\n    // Idempotent: if index not found, treat as success\n    if (e.getMessage() != null && e.getMessage().contains(\"not found\")) return;\n    throw e;\n}","preventionTips":["Always check index existence before delete to avoid unnecessary exceptions.","Make delete operations idempotent in the calling layer.","Chain the IOException cause for diagnostic visibility."],"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"}