Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searchkick manually remove specific record Index

How I can manually remove specific record Index using Searchkick. There is option to reindex the specific record but i didnt find any option to delete a record index.

 product = Product.find 10
 product.reindex
like image 608
kashif Avatar asked Feb 24 '15 11:02

kashif


3 Answers

What if you only have the id of the deleted model? eg. in the case where you are getting the call in a background worker?

Looking at the source code, searchkick only checks the class of the object to work out the index and grabs the id from the object, so you could do something like this to get around it:

# given value id holding the record id of the deleted model record (eg. Product with id 123)

prod = Product.new(id: id)

Product.searchkick_index.remove(prod)

Hacky but works :P

like image 118
foomip Avatar answered Oct 12 '22 23:10

foomip


If anyone's looking for how to delete & blow away the entire index to start off fresh you can do it as so:

MyModel.searchkick_index.delete &&  MyModel.searchkick_index.create
like image 24
Nathan Bertram Avatar answered Nov 16 '22 03:11

Nathan Bertram


To remove from index:

product = Product.find 10
Product.searchkick_index.remove(product)
like image 22
Rodrigo Avatar answered Nov 16 '22 03:11

Rodrigo