diff --git a/CHANGELOG.md b/CHANGELOG.md index 3968e54..da4937b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Changed async reindex to fetch ids instead of using ranges for numeric primary keys with Active Record - Changed `searchkick_index_options` to return symbol keys (instead of mix of strings and symbols) - Changed non-anchored regular expressions to match expected results (previously warned) +- Updated async reindex job to call `search_import` for nested associations - Fixed removing records when `should_index?` is `false` when `reindex` called on relation - Fixed issue with `merge_mappings` for fields that use `searchkick` options - Raise error when `search` called on relations diff --git a/lib/searchkick/process_batch_job.rb b/lib/searchkick/process_batch_job.rb index 42c13b3..b543158 100644 --- a/lib/searchkick/process_batch_job.rb +++ b/lib/searchkick/process_batch_job.rb @@ -13,9 +13,7 @@ module Searchkick {id: parts[0], routing: parts[1]} end - relation = klass - relation = relation.search_import if relation.respond_to?(:search_import) - index.send(:record_indexer).reindex_items(relation, items, method_name: nil) + index.send(:record_indexer).reindex_items(klass, items, method_name: nil) end end end diff --git a/lib/searchkick/record_indexer.rb b/lib/searchkick/record_indexer.rb index 54b4403..1335ef3 100644 --- a/lib/searchkick/record_indexer.rb +++ b/lib/searchkick/record_indexer.rb @@ -59,7 +59,10 @@ module Searchkick routing = items.to_h { |r| [r[:id], r[:routing]] } record_ids = routing.keys - records = Searchkick.load_records(klass, record_ids).select(&:should_index?) + relation = Searchkick.load_records(klass, record_ids) + # call search_import even for single records for nested associations + relation = relation.search_import if relation.respond_to?(:search_import) + records = relation.select(&:should_index?) # determine which records to delete delete_ids = record_ids - records.map { |r| r.id.to_s } -- libgit2 0.21.0