Searchkick: Change the default query of reindex method

Created on 22 Sep 2016  路  3Comments  路  Source: ankane/searchkick

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!

question

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings