Module: Elasticsearch::Model::Adapter::Mongoid::Importing

Defined in:
lib/elasticsearch/model/adapters/mongoid.rb

Instance Method Summary collapse

Instance Method Details

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

Fetch batches of records from the database



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/elasticsearch/model/adapters/mongoid.rb', line 83

def __find_in_batches(options={}, &block)
  batch_size = options[:batch_size] || 1_000
  query = options[:query]
  named_scope = options[:scope]
  preprocess = options[:preprocess]

  scope = all
  scope = scope.send(named_scope) if named_scope
  scope = query.is_a?(Proc) ? scope.class_exec(&query) : scope.where(query) if query
  scope.no_timeout.each_slice(batch_size) do |items|
    yield (preprocess ? self.__send__(preprocess, items) : items)
  end
end

#__transformObject



97
98
99
# File 'lib/elasticsearch/model/adapters/mongoid.rb', line 97

def __transform
  lambda { |a| { index: { _id: a.id.to_s, data: a.as_indexed_json } } }
end