简体   繁体   中英

Rails Elastic Search reindex data after update_all

I am using Searchkick for interacting with elastic search api in my Rails app, and it's working fine almost for all the cases, but the problem I am facing is I am having status field in my Model, and through select all check box a User can change the status of all the records, so I am updating my data using update_all which doesn't fire any callback, and searchkick reindex data through after_commit callback. and since, my data is not getting reindexed in Elastic Search this way it's giving same results, what I am suppose to do, is calling Model.reindex manually is a good option??

I actually solved it, without re indexing whole data which would have been a really naive solution, instead of that we can also re index a single record Like below

product = Product.find 10
product.reindex
# or to reindex in the background
product.reindex_async

You have to call Model.reindex manually. action_all is build to make changes at DB level directly. Find more here .

You can create after_action filter to reindex data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM