From 75e16164bca733d02d861412596f6c50d62b206c Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 15 Dec 2015 21:24:17 -0800 Subject: [PATCH] Faster import for multiple document types --- lib/searchkick/index.rb | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/searchkick/index.rb b/lib/searchkick/index.rb index 795d306..515aaf5 100644 --- a/lib/searchkick/index.rb +++ b/lib/searchkick/index.rb @@ -45,12 +45,7 @@ module Searchkick # record based def store(record) - client.index( - index: name, - type: document_type(record), - id: search_id(record), - body: search_data(record) - ) + import([record]) end def remove(record) @@ -65,16 +60,13 @@ module Searchkick end def import(records) - records.group_by { |r| document_type(r) }.each do |type, batch| - response = - client.bulk( - index: name, - type: type, - body: batch.map { |r| {index: {_id: search_id(r), data: search_data(r)}} } - ) - if response["errors"] - raise Searchkick::ImportError, response["items"].first["index"]["error"] - end + response = + client.bulk( + index: name, + body: records.map { |r| {index: {_id: search_id(r), _type: document_type(r), data: search_data(r)}} } + ) + if response["errors"] + raise Searchkick::ImportError, response["items"].first["index"]["error"] end end -- libgit2 0.21.0