Class: Elasticsearch::Model::TransactionalCallbacks::BulkIndexingJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/elasticsearch/model/transactional_callbacks/bulk_indexing_job.rb

Overview

Background job which handles the request to index/update/delete documents asynchronously

Elasticsearch::Model::TransactionalCallbacks::BulkIndexingJob.perform_later(
  document_type: {
    index: [{ _id: document.id }],
    update: [{ _id: document.id }],
    delete: [{ _id: document.id }],
  }
)

Instance Method Summary collapse

Instance Method Details

#perform(indexables) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/elasticsearch/model/transactional_callbacks/bulk_indexing_job.rb', line 20

def perform(indexables)
  indexables.each do |document_type, action_map|
    klass = document_type.to_s.camelcase.constantize
    body = transform_batches(klass, action_map)

    response = bulk_index klass, body

    ::Rails.logger.error "[ELASTICSEARCH] Bulk request failed: #{response['items']}" if response&.dig('errors')
  end
end