Hi,
I'm trying to change the default query that is performed when run i'm running the method reindex.
Eg:
# schema.rb
create_table "products", force: :cascade do |t|
t.string "name"
t.boolean "active"
end
Product Load (40.1ms) SELECT "products".* FROM "products" ORDER BY "products"."id" ASC LIMIT 1000
Product Import (1846.6ms) {"count":379}
Product Load (50.4ms) SELECT "products".* FROM "products" WHERE ("products"."id" > 1113) ORDER BY "products"."id" ASC LIMIT 1000
Product Import (4009.4ms) {"count":492}
In this case, the searchkick only index active products but the query get all products.
Can i change or configure to execute the index query like this:
SELECT "products".* FROM "products" WHERE active = true ORDER BY "products"."id" ASC LIMIT 1000
Thanks!
Hey @raphaelcuba, you can use the search_import scope. More info here: https://github.com/ankane/searchkick#indexing
@ankane what you think about improve the docs about "Indexing" with the following information:
"Searchkick uses find_in_batches to import documents. To eager load associations or update the default query used to reindex, use the search_import scope."
Good idea, I updated the example to be more complete.