Last Updated: February 25, 2016
·
340
· nisanth074

Remove ActiveRecord model from ElasticSearch index with tire gem

Say, we have an ActiveRecord model Ticket

class Ticket < ActiveRecord::Base
  # Tire setup
  # ...
end

We can delete a Ticket instance, if we know its ID

document_id = ticket.id
Ticket.index.remove(Ticket.document_type, document_id)

Quite handy, if a model is deleted, but a corresponding delete didn't happen in ElasticSearch (the backgrounded index updater failed due to network failure etc.)