Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 876 Bytes

File metadata and controls

43 lines (33 loc) · 876 Bytes
endpoint delete
lang ruby
es_version 9.3
client elasticsearch==9.3.0

Elasticsearch 9.3 delete endpoint (Ruby example)

Use client.delete to remove a document by its ID.

response = client.delete(index: 'products', id: 'prod-1')
puts "#{response['result']} document #{response['_id']}"

Handling missing documents

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'
end

Conditional deletes

Use 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']
)