Commit 92c86d6288d682c1c7ce4f1f549a1ed3a4b5e7fc

Authored by Andrew Kane
1 parent e0cf73d2

Determine id consistently

Showing 1 changed file with 7 additions and 3 deletions   Show diff stats
lib/searchkick/index.rb
... ... @@ -26,7 +26,7 @@ module Searchkick
26 26 client.index(
27 27 index: name,
28 28 type: document_type(record),
29   - id: record.id,
  29 + id: search_id(record),
30 30 body: search_data(record)
31 31 )
32 32 end
... ... @@ -35,7 +35,7 @@ module Searchkick
35 35 client.delete(
36 36 index: name,
37 37 type: document_type(record),
38   - id: record.id
  38 + id: search_id(record)
39 39 )
40 40 end
41 41  
... ... @@ -44,7 +44,7 @@ module Searchkick
44 44 client.bulk(
45 45 index: name,
46 46 type: type,
47   - body: batch.map{|r| data = search_data(r); {index: {_id: data["_id"] || data["id"] || r.id, data: data}} }
  47 + body: batch.map{|r| data = search_data(r); {index: {_id: search_id(r), data: data}} }
48 48 )
49 49 end
50 50 end
... ... @@ -71,6 +71,10 @@ module Searchkick
71 71 klass_document_type(record.class)
72 72 end
73 73  
  74 + def search_id(record)
  75 + record.id.is_a?(Numeric) ? record.id : record.id.to_s
  76 + end
  77 +
74 78 def search_data(record)
75 79 source = record.search_data
76 80  
... ...