class Searchkick::Indexer

Attributes

queued_items[R]

Public Class Methods

new() click to toggle source
# File lib/searchkick/indexer.rb, line 5
def initialize
  @queued_items = []
end

Public Instance Methods

perform() click to toggle source
# File lib/searchkick/indexer.rb, line 14
def perform
  items = @queued_items
  @queued_items = []
  if items.any?
    response = Searchkick.client.bulk(body: items)
    if response["errors"]
      first_with_error = response["items"].map do |item|
        (item["index"] || item["delete"] || item["update"])
      end.find { |item| item["error"] }
      raise Searchkick::ImportError, "#{first_with_error["error"]} on item with id '#{first_with_error["_id"]}'"
    end
  end
end
queue(items) click to toggle source
# File lib/searchkick/indexer.rb, line 9
def queue(items)
  @queued_items.concat(items)
  perform unless Searchkick.callbacks_value == :bulk
end