Remove/Delete an indexed document in ElasticSearch with Tire (with soft delete via ActsAsParanoid)
Asked Answered
C

2

6

I have an ElasticSearch server running that indexes and searched documents using the excellent Tire gem. Everything works great, except I'm not sure how to go about manually removing documents from the search index.

I have poured over the RDoc and searched for hours, but this is the only hint at a solution I can find https://github.com/karmi/tire/issues/309. Is there an easier way other than building a custom wrapper around curl and making the request manually?

Another hitch is that I use a soft-delete gem called ActsAsParanoid, so the Tire::Model::Callbacks won't remove the object on soft-delete.

Any ideas?

Counterwork answered 9/10, 2012 at 14:28 Comment(0)
E
10

In case you only have the ID (e.g. 12345):

User.tire.index.remove 'user', '12345'

Or more generally:

klass.tire.index.remove klass.document_type, record_id

(which I think is equivalent to what remove @user will do behind the scenes)

reference

Exasperate answered 5/9, 2013 at 11:37 Comment(0)
C
6

Turns out you can just manually remove the soft-deleted Object from the index like so:

@user = User.find(id) #or whatever your indexed object is
User.tire.index.remove @user #this will remove them from the index

Thats it!

Counterwork answered 9/10, 2012 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.