Module: Elasticsearch::Model::Importing::ClassMethods
- Defined in:
- lib/elasticsearch/model/importing.rb
Instance Method Summary collapse
-
#import(options = {}, &block) {|Hash| ... } ⇒ Fixnum
Import all model records into the index.
Instance Method Details
#import(options = {}, &block) {|Hash| ... } ⇒ Fixnum
Import all model records into the index
The method will pick up correct strategy based on the ‘Importing` module defined in the corresponding adapter.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/elasticsearch/model/importing.rb', line 67 def import(={}, &block) errors = 0 refresh = .delete(:refresh) || false target_index = .delete(:index) || index_name target_type = .delete(:type) || document_type if .delete(:force) self.create_index! force: true, index: target_index end __find_in_batches() do |batch| response = client.bulk \ index: target_index, type: target_type, body: batch yield response if block_given? errors += response['items'].map { |k, v| k.values.first['error'] }.compact.length end self.refresh_index! if refresh return errors end |