Module: ElasticRecord::Relation::Batches
- Included in:
- ElasticRecord::Relation
- Defined in:
- lib/elastic_record/relation/batches.rb
Instance Method Summary collapse
Instance Method Details
#find_each ⇒ Object
4 5 6 7 8 |
# File 'lib/elastic_record/relation/batches.rb', line 4 def find_each find_in_batches do |records| records.each { |record| yield record } end end |
#find_in_batches(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/elastic_record/relation/batches.rb', line 10 def find_in_batches( = {}) scroll_keep_alive = '10m' = { scroll: scroll_keep_alive, size: 100, search_type: 'scan' } scroll_id = klass.elastic_index.search(as_elastic, )['_scroll_id'] while (hit_ids = get_scroll_hit_ids(scroll_id, scroll_keep_alive)).any? yield klass.find(hit_ids) end end |
#reindex ⇒ Object
26 27 28 29 30 |
# File 'lib/elastic_record/relation/batches.rb', line 26 def reindex relation.find_in_batches do |batch| elastic_index.bulk_add(batch) end end |