Commit 05bde2abd78299bff47ec0e64d6feed68dd6ab81
1 parent
80f8811a
Exists in
master
and in
21 other branches
Fixed reindex with inheritance - closes #194
Showing
2 changed files
with
10 additions
and
3 deletions
Show diff stats
lib/searchkick/index.rb
@@ -40,11 +40,11 @@ module Searchkick | @@ -40,11 +40,11 @@ module Searchkick | ||
40 | end | 40 | end |
41 | 41 | ||
42 | def import(records) | 42 | def import(records) |
43 | - if records.any? | 43 | + records.group_by{|r| document_type(r) }.each do |type, batch| |
44 | client.bulk( | 44 | client.bulk( |
45 | index: name, | 45 | index: name, |
46 | - type: document_type(records.first), | ||
47 | - body: records.map{|r| data = search_data(r); {index: {_id: data["_id"] || data["id"] || r.id, data: data}} } | 46 | + type: type, |
47 | + body: batch.map{|r| data = search_data(r); {index: {_id: data["_id"] || data["id"] || r.id, data: data}} } | ||
48 | ) | 48 | ) |
49 | end | 49 | end |
50 | end | 50 | end |
test/inheritance_test.rb
@@ -62,6 +62,13 @@ class TestInheritance < Minitest::Unit::TestCase | @@ -62,6 +62,13 @@ class TestInheritance < Minitest::Unit::TestCase | ||
62 | assert_equal ["tiger"], Animal.search("tige", fields: [:name], suggest: true).suggestions.sort | 62 | assert_equal ["tiger"], Animal.search("tige", fields: [:name], suggest: true).suggestions.sort |
63 | end | 63 | end |
64 | 64 | ||
65 | + def test_reindex | ||
66 | + store_names ["Bear A"], Cat | ||
67 | + store_names ["Bear B"], Dog | ||
68 | + Animal.reindex | ||
69 | + assert_equal 1, Dog.search("bear").size | ||
70 | + end | ||
71 | + | ||
65 | # TODO move somewhere better | 72 | # TODO move somewhere better |
66 | 73 | ||
67 | def test_multiple_indices | 74 | def test_multiple_indices |