{"record":{"id":"8b7545cc2d7e3524","repo":"alibaba/spring-ai-alibaba","slug":"delete-operation-failed","errorCode":null,"errorMessage":"Delete operation failed","messagePattern":"Delete operation failed","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java","lineNumber":223,"sourceCode":"\t\t\t\t\tthrow new IllegalStateException(bulkResponseItem.error().reason());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tpublic void doDelete(List<String> idList) {\n\t\tBulkRequest.Builder bulkRequestBuilder = new BulkRequest.Builder();\n\t\t// For the index to be present, either it must be pre-created or set the\n\t\t// initializeSchema to true.\n\t\tif (!indexExists()) {\n\t\t\tthrow new IllegalArgumentException(\"Index not found\");\n\t\t}\n\t\tfor (String id : idList) {\n\t\t\tbulkRequestBuilder.operations(op -> op.delete(idx -> idx.index(this.options.getIndexName()).id(id)));\n\t\t}\n\t\tif (bulkRequest(bulkRequestBuilder.build()).errors()) {\n\t\t\tthrow new IllegalStateException(\"Delete operation failed\");\n\t\t}\n\t}\n\n\t@Override\n\tpublic void doDelete(Filter.Expression filterExpression) {\n\t\t// For the index to be present, either it must be pre-created or set the\n\t\t// initializeSchema to true.\n\t\tif (!indexExists()) {\n\t\t\tthrow new IllegalArgumentException(\"Index not found\");\n\t\t}\n\n\t\ttry {\n\t\t\tthis.elasticsearchClient.deleteByQuery(d -> d.index(this.options.getIndexName())\n\t\t\t\t.query(q -> q.queryString(qs -> qs.query(getElasticsearchQueryString(filterExpression)))));\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new IllegalStateException(\"Failed to delete documents by filter\", e);\n\t\t}","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java#L205-L241","documentation":"After issuing a bulk delete by ids, doDelete checks BulkResponse.errors(); if Elasticsearch reports any per-item failure it throws IllegalStateException(\"Delete operation failed\"). The index existed, but one or more delete operations in the bulk request did not succeed.","triggerScenarios":"Calling VectorStore.delete(ids) where the bulk response reports item-level errors — typically document version conflicts, routing mismatches, or partial cluster failures during the bulk delete.","commonSituations":"Concurrent writers causing version conflicts (409); shard unavailability due to red cluster health; deleted-under-you documents with strict versioning; network interruptions mid-bulk.","solutions":["Inspect the BulkResponse item failures (Elasticsearch returns per-item error details) to identify the failing documents.","Retry the failed deletes; delete-by-id of a missing doc is normally idempotent, so conflicts are usually transient.","Check cluster health (yellow/green shards required) and resolve unassigned shards.","Consider per-item error handling or lower concurrency if version conflicts from concurrent writes are the cause."],"exampleFix":"// before\nif (bulkRequest(bulkRequestBuilder.build()).errors()) {\n    throw new IllegalStateException(\"Delete operation failed\");\n}\n// after\nBulkResponse resp = bulkRequest(bulkRequestBuilder.build());\nif (resp.errors()) {\n    for (BulkResponseItem item : resp.items()) { if (item.error() != null) logger.error(\"delete failed: {} {}\", item.id(), item.error().reason()); }\n    throw new IllegalStateException(\"Delete operation failed for some documents\");\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { vectorStore.delete(ids); } catch (IllegalStateException e) {\n    log.warn(\"bulk delete failed, retrying\", e);\n    retryExecutor.execute(() -> vectorStore.delete(ids)); // idempotent by id\n}","preventionTips":["Treat delete-by-id as idempotent and retry transient bulk failures.","Keep cluster health green; monitor unassigned shards.","Reduce write concurrency or use optimistic concurrency controls to avoid 409 version conflicts.","Capture per-item bulk errors server-side for diagnosis instead of only a generic flag."],"tags":["elasticsearch","vector-store","bulk-delete"],"backgroundTag":"database-write-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}