Searchkick:无法找到原始记录时删除文档

Searchkick: Remove documents when unable to find original record

举另一个问题的例子

product = Product.find(10) 
   `raise_record_not_found_exception!'
product.nil?
=> true

product = Product.search "*", where: {id: 10}, load: false
product.count
=> 1

如何在没有干净擦拭的情况下取出文档?

谢谢

这是由跳过回调的 default in Searchkick, unless you removed this record by use some methods 完成的。

来自 Searchkick 的引述:

There are four strategies for keeping the index synced with your database.

Immediate (default) Anytime a record is inserted, updated, or deleted

Asynchronous Use background jobs for better performance ...

如果您的索引与数据库不同步并且您不想进行完整的重建索引,您可以这样做:

missing_product = Product.new
missing_product.id = 10
Product.search_index.remove(missing_product)