Module: Elasticsearch::Model::Adapter::ActiveRecord::Importing

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

Instance Method Summary collapse

Instance Method Details

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

Fetch batches of records from the database (used by the import method)



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/elasticsearch/model/adapters/active_record.rb', line 99

def __find_in_batches(options={}, &block)
  query = options.delete(:query)
  named_scope = options.delete(:scope)
  preprocess = options.delete(:preprocess)

  scope = self
  scope = scope.__send__(named_scope) if named_scope
  scope = scope.instance_exec(&query) if query

  scope.find_in_batches(options) do |batch|
    yield (preprocess ? self.__send__(preprocess, batch) : batch)
  end
end

#__transformObject



113
114
115
# File 'lib/elasticsearch/model/adapters/active_record.rb', line 113

def __transform
  lambda { |model|  { index: { _id: model.id, data: model.__elasticsearch__.as_indexed_json } } }
end