{"record":{"id":"84868543384d3652","repo":"spring-projects/spring-ai","slug":"delete-operation-failed","errorCode":null,"errorMessage":"Delete operation failed","messagePattern":"Delete operation failed","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java","lineNumber":223,"sourceCode":"\t\t\t}\n\t\t}\n\t}\n\n\tprivate Object getDocument(Document document, float[] embedding, String embeddingFieldName) {\n\t\tAssert.notNull(document.getText(), \"document's text must not be null\");\n\n\t\treturn Map.of(\"id\", document.getId(), \"content\", document.getText(), \"metadata\", document.getMetadata(),\n\t\t\t\tembeddingFieldName, embedding);\n\t}\n\n\t@Override\n\tpublic void doDelete(List<String> idList) {\n\t\tBulkRequest.Builder bulkRequestBuilder = new BulkRequest.Builder();\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\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}\n\t}\n\n\tprivate BulkResponse bulkRequest(BulkRequest bulkRequest) {\n\t\ttry {\n\t\t\treturn this.elasticsearchClient.bulk(bulkRequest);\n\t\t}","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java#L205-L241","documentation":"ElasticsearchVectorStore.doDelete(List<String>) issues a BulkRequest of delete operations; if the BulkResponse reports errors(), it throws IllegalStateException(\"Delete operation failed\"). The individual item errors are not inspected, so any single failing delete (missing doc, version conflict, index closed) causes this blanket failure.","triggerScenarios":"Calling vectorStore.delete(List<String> ids) where at least one bulk delete item fails in Elasticsearch (document not found with strict settings, version conflict, index missing/readonly).","commonSituations":"Deleting documents already removed by another process, index in read-only mode due to disk watermark, wrong index name configured in ElasticsearchVectorStoreOptions, or concurrent writes causing conflicts.","solutions":["Inspect Elasticsearch cluster logs / bulk response item failures for the concrete per-item error","Verify options.getIndexName() matches an existing, writable index","Check cluster disk watermarks and index read-only blocks (index.blocks.read_only_allow_delete)","Retry with valid IDs; accept 404s for idempotent deletes by checking existence first"],"exampleFix":"// before: blind delete of possibly-removed docs\ndelete(List.of(\"doc-1\", \"doc-2\"));\n// after: filter to existing docs\nList<String> existing = ids.stream().filter(id -> documentExists(id)).toList();\nif (!existing.isEmpty()) delete(existing);","handlingStrategy":"validation","validationCode":"List<String> existing = ids.stream()\n    .filter(id -> elasticsearchClient.get(g -> g.index(indexName).id(id), Map.class).found())\n    .toList();\nif (!existing.isEmpty()) vectorStore.delete(existing);","typeGuard":null,"tryCatchPattern":"try {\n    vectorStore.delete(ids);\n} catch (IllegalStateException e) {\n    logger.warn(\"Some bulk deletes failed; inspect ES item errors\", e);\n}","preventionTips":["Check index is writable (no read_only block, disk watermarks OK)","Verify indexName configuration before deletes","Treat deletes as idempotent and tolerate missing-document 404s"],"tags":["elasticsearch","vector-store","delete","bulk-request"],"backgroundTag":"database-write-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}