Module: Elasticsearch::Model::Adapter::Mongoid::Importing
- Defined in:
- lib/elasticsearch/model/adapters/mongoid.rb
Instance Method Summary collapse
-
#__find_in_batches(options = {}, &block) ⇒ Object
Fetch batches of records from the database.
Instance Method Details
#__find_in_batches(options = {}, &block) ⇒ Object
Fetch batches of records from the database
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/elasticsearch/model/adapters/mongoid.rb', line 65 def __find_in_batches(={}, &block) [:batch_size] ||= 1_000 items = [] all.each do |item| items << item if items.length % [:batch_size] == 0 batch_for_bulk = items.map { |a| { index: { _id: a.id.to_s, data: a.as_indexed_json } } } yield batch_for_bulk items = [] end end unless items.empty? batch_for_bulk = items.map { |a| { index: { _id: a.id.to_s, data: a.as_indexed_json } } } yield batch_for_bulk end end |