Module: Elasticsearch::Model::Adapter::Mongoid::Importing
- Defined in:
- lib/elasticsearch/model/adapters/mongoid.rb
Instance Method Summary collapse
-
#__find_in_batches(options = {}, &block) ⇒ Object
Fetch batches of records from the database.
- #__transform ⇒ Object
Instance Method Details
#__find_in_batches(options = {}, &block) ⇒ Object
Fetch batches of records from the database
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/elasticsearch/model/adapters/mongoid.rb', line 65 def __find_in_batches(={}, &block) batch_size = [:batch_size] || 1_000 query = [:query] named_scope = [:scope] preprocess = [: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 |
#__transform ⇒ Object
80 81 82 |
# File 'lib/elasticsearch/model/adapters/mongoid.rb', line 80 def __transform lambda {|a| { index: { _id: a.id.to_s, data: a.as_indexed_json } }} end |