Commit 75e16164bca733d02d861412596f6c50d62b206c

Authored by Andrew Kane
1 parent c168c3fa

Faster import for multiple document types

Showing 1 changed file with 8 additions and 16 deletions   Show diff stats
lib/searchkick/index.rb
@@ -45,12 +45,7 @@ module Searchkick @@ -45,12 +45,7 @@ module Searchkick
45 # record based 45 # record based
46 46
47 def store(record) 47 def store(record)
48 - client.index(  
49 - index: name,  
50 - type: document_type(record),  
51 - id: search_id(record),  
52 - body: search_data(record)  
53 - ) 48 + import([record])
54 end 49 end
55 50
56 def remove(record) 51 def remove(record)
@@ -65,16 +60,13 @@ module Searchkick @@ -65,16 +60,13 @@ module Searchkick
65 end 60 end
66 61
67 def import(records) 62 def import(records)
68 - records.group_by { |r| document_type(r) }.each do |type, batch|  
69 - response =  
70 - client.bulk(  
71 - index: name,  
72 - type: type,  
73 - body: batch.map { |r| {index: {_id: search_id(r), data: search_data(r)}} }  
74 - )  
75 - if response["errors"]  
76 - raise Searchkick::ImportError, response["items"].first["index"]["error"]  
77 - end 63 + response =
  64 + client.bulk(
  65 + index: name,
  66 + body: records.map { |r| {index: {_id: search_id(r), _type: document_type(r), data: search_data(r)}} }
  67 + )
  68 + if response["errors"]
  69 + raise Searchkick::ImportError, response["items"].first["index"]["error"]
78 end 70 end
79 end 71 end
80 72