| endpoint | lang | es_version | client |
|---|---|---|---|
delete |
java |
9.3 |
co.elastic.clients:elasticsearch-java:9.3.0 |
Use client.delete() to remove a document by its ID.
var response = client.delete(d -> d
.index("products")
.id("prod-1")
);
System.out.println(response.result() + " document " + response.id());Check the result to determine if the document existed:
var response = client.delete(d -> d.index("products").id("prod-999"));
if (response.result() == Result.NotFound) {
System.out.println("Document not found — nothing to delete");
}Use ifSeqNo and ifPrimaryTerm for optimistic concurrency control:
var doc = client.get(g -> g.index("products").id("prod-1"), Product.class);
client.delete(d -> d
.index("products")
.id("prod-1")
.ifSeqNo(doc.seqNo())
.ifPrimaryTerm(doc.primaryTerm())
);