instances_index_importer.rb 505 B

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. class Importer::InstancesIndexImporter < Importer::BaseImporter
  3. def import!
  4. index.adapter.default_scope.find_in_batches(batch_size: @batch_size) do |tmp|
  5. in_work_unit(tmp) do |instances|
  6. bulk = build_bulk_body(instances)
  7. indexed = bulk.size
  8. deleted = 0
  9. Chewy::Index::Import::BulkRequest.new(index).perform(bulk)
  10. [indexed, deleted]
  11. end
  12. end
  13. wait!
  14. end
  15. private
  16. def index
  17. InstancesIndex
  18. end
  19. end