| endpoint | delete |
|---|---|
| lang | ruby |
| es_version | 9.3 |
| client | elasticsearch==9.3.0 |
Use client.delete to remove a document by its ID.
response = client.delete(index: 'products', id: 'prod-1')
puts "#{response['result']} document #{response['_id']}"A NotFound error is raised when the document does not exist:
begin
client.delete(index: 'products', id: 'prod-999')
rescue Elastic::Transport::Transport::Errors::NotFound
puts 'Document not found — nothing to delete'
endUse if_seq_no and if_primary_term for optimistic concurrency
control:
doc = client.get(index: 'products', id: 'prod-1')
client.delete(
index: 'products',
id: 'prod-1',
if_seq_no: doc['_seq_no'],
if_primary_term: doc['_primary_term']
)