Module: ElasticRecord::Relation::Batches

Included in:
ElasticRecord::Relation
Defined in:
lib/elastic_record/relation/batches.rb

Instance Method Summary collapse

Instance Method Details

#build_scroll_enumerator(options) ⇒ Object



20
21
22
# File 'lib/elastic_record/relation/batches.rb', line 20

def build_scroll_enumerator(options)
  elastic_index.build_scroll_enumerator(search: as_elastic, **options)
end

#find_each(options = {}) ⇒ Object



4
5
6
7
8
# File 'lib/elastic_record/relation/batches.rb', line 4

def find_each(options = {})
  find_in_batches(options) do |records|
    records.each { |record| yield record }
  end
end

#find_ids_in_batches(options = {}, &block) ⇒ Object



16
17
18
# File 'lib/elastic_record/relation/batches.rb', line 16

def find_ids_in_batches(options = {}, &block)
  build_scroll_enumerator(options).each_slice(&block)
end

#find_in_batches(options = {}) ⇒ Object



10
11
12
13
14
# File 'lib/elastic_record/relation/batches.rb', line 10

def find_in_batches(options = {})
  find_ids_in_batches(options) do |ids|
    yield klass.where(id: ids)
  end
end

#reindexObject



24
25
26
27
28
# File 'lib/elastic_record/relation/batches.rb', line 24

def reindex
  relation.find_in_batches do |batch|
    elastic_index.bulk_add(batch)
  end
end