alibaba/spring-ai-alibaba · error · IllegalStateException

Delete operation failed

Error message

Delete operation failed

What it means

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.

Solutions

  1. Inspect the BulkResponse item failures (Elasticsearch returns per-item error details) to identify the failing documents.
  2. Retry the failed deletes; delete-by-id of a missing doc is normally idempotent, so conflicts are usually transient.
  3. Check cluster health (yellow/green shards required) and resolve unassigned shards.
  4. Consider per-item error handling or lower concurrency if version conflicts from concurrent writes are the cause.

Example fix

// before
if (bulkRequest(bulkRequestBuilder.build()).errors()) {
    throw new IllegalStateException("Delete operation failed");
}
// after
BulkResponse resp = bulkRequest(bulkRequestBuilder.build());
if (resp.errors()) {
    for (BulkResponseItem item : resp.items()) { if (item.error() != null) logger.error("delete failed: {} {}", item.id(), item.error().reason()); }
    throw new IllegalStateException("Delete operation failed for some documents");
}
Defensive patterns

Strategy: retry

Try / catch

try { vectorStore.delete(ids); } catch (IllegalStateException e) {
    log.warn("bulk delete failed, retrying", e);
    retryExecutor.execute(() -> vectorStore.delete(ids)); // idempotent by id
}

Prevention

When it happens

Trigger: 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.

Common situations: Concurrent writers causing version conflicts (409); shard unavailability due to red cluster health; deleted-under-you documents with strict versioning; network interruptions mid-bulk.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/8b7545cc2d7e3524. Report an issue: GitHub.

Appendix: source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java:223

					throw new IllegalStateException(bulkResponseItem.error().reason());
				}
			}
		}
	}

	@Override
	public void doDelete(List<String> idList) {
		BulkRequest.Builder bulkRequestBuilder = new BulkRequest.Builder();
		// For the index to be present, either it must be pre-created or set the
		// initializeSchema to true.
		if (!indexExists()) {
			throw new IllegalArgumentException("Index not found");
		}
		for (String id : idList) {
			bulkRequestBuilder.operations(op -> op.delete(idx -> idx.index(this.options.getIndexName()).id(id)));
		}
		if (bulkRequest(bulkRequestBuilder.build()).errors()) {
			throw new IllegalStateException("Delete operation failed");
		}
	}

	@Override
	public void doDelete(Filter.Expression filterExpression) {
		// For the index to be present, either it must be pre-created or set the
		// initializeSchema to true.
		if (!indexExists()) {
			throw new IllegalArgumentException("Index not found");
		}

		try {
			this.elasticsearchClient.deleteByQuery(d -> d.index(this.options.getIndexName())
				.query(q -> q.queryString(qs -> qs.query(getElasticsearchQueryString(filterExpression)))));
		}
		catch (Exception e) {
			throw new IllegalStateException("Failed to delete documents by filter", e);
		}

View on GitHub (pinned to f82da0b50f)