Module: ElasticRecord::Batches
- Included in:
- Relation
- Defined in:
- lib/elastic_record/relation/batches.rb
Instance Method Summary collapse
Instance Method Details
#find_each ⇒ Object
3 4 5 6 7 |
# File 'lib/elastic_record/relation/batches.rb', line 3 def find_each find_in_batches do |records| records.each { |record| yield record } end end |
#find_in_batches(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/elastic_record/relation/batches.rb', line 9 def find_in_batches( = {}) [:size] ||= 100 [:scroll] ||= '20m' [:search_type] = 'scan' hits = klass.elastic_connection.search(as_elastic, ) klass.elastic_connection.scroll(hits.scroll_id, scroll: [:scroll], ids_only: true) do |hits| yield klass.find(hits.to_a) end end |
#reindex ⇒ Object
21 22 23 24 25 |
# File 'lib/elastic_record/relation/batches.rb', line 21 def reindex relation.find_in_batches do |batch| elastic_index.bulk_add(batch) end end |