Configure indexing sync strategies
masterSearchkick provides four strategies for keeping your index in sync with your database:
- Inline (default): Updates are performed immediately during record insertion, update, or deletion.
- Asynchronous: Uses background jobs for better performance. Add
searchkick callbacks: :asyncto your model. Jobs are added to a queue namedsearchkick. - Queuing: Pushes record IDs to a queue to be reindexed in batches in the background. This is more performant than the asynchronous method.
- Manual: Disables automatic syncing with
searchkick callbacks: false. You must then call.reindexon records or relations manually.
You can also override a specific instance's strategy using reindex(mode: :async) or reindex(mode: :queue).
# Asynchronous strategy
class Product < ApplicationRecord
searchkick callbacks: :async
end
# Manual strategy
class Product < ApplicationRecord
searchkick callbacks: false
end
# Manual reindexing
product.reindex
# or
store.products.reindex(mode: :async)
# Bulk updates
Searchkick.callbacks(:bulk) do
Product.find_each(&:update_fields)
end
# Temporarily skip updates
Searchkick.callbacks(false) do
Product.find_each(&:update_fields)
end