lib/searchkick/index.rb in searchkick-1.5.0 vs lib/searchkick/index.rb in searchkick-1.5.1
- old
+ new
@@ -7,12 +7,12 @@
def initialize(name, options = {})
@name = name
@options = options
end
- def create(options = {})
- client.indices.create index: name, body: options
+ def create(body = {})
+ client.indices.create index: name, body: body
end
def delete
client.indices.delete index: name
end
@@ -57,20 +57,20 @@
def remove(record)
bulk_delete([record])
end
def bulk_delete(records)
- Searchkick.queue_items(records.reject { |r| r.id.blank? }.map { |r| {delete: record_data(r)} })
+ Searchkick.indexer.queue(records.reject { |r| r.id.blank? }.map { |r| {delete: record_data(r)} })
end
def bulk_index(records)
- Searchkick.queue_items(records.map { |r| {index: record_data(r).merge(data: search_data(r))} })
+ Searchkick.indexer.queue(records.map { |r| {index: record_data(r).merge(data: search_data(r))} })
end
alias_method :import, :bulk_index
def bulk_update(records, method_name)
- Searchkick.queue_items(records.map { |r| {update: record_data(r).merge(data: {doc: search_data(r, method_name)})} })
+ Searchkick.indexer.queue(records.map { |r| {update: record_data(r).merge(data: {doc: search_data(r, method_name)})} })
end
def record_data(r)
data = {
_index: name,
@@ -255,10 +255,19 @@
import_or_update items, method_name
end
end
def import_or_update(records, method_name)
- method_name ? bulk_update(records, method_name) : import(records)
+ retries = 0
+ begin
+ method_name ? bulk_update(records, method_name) : import(records)
+ rescue Faraday::ClientError => e
+ if retries < 1
+ retries += 1
+ retry
+ end
+ raise e
+ end
end
# other
def tokens(text, options = {})