Class: Supple::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/supple/model.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope, index_name, document_type) ⇒ Importer

Returns a new instance of Importer.



10
11
12
13
14
# File 'lib/supple/model.rb', line 10

def initialize(scope, index_name, document_type)
  @scope = scope
  @index_name = index_name
  @document_type = document_type
end

Instance Method Details

#execute!Object



16
17
18
19
20
21
22
23
24
# File 'lib/supple/model.rb', line 16

def execute!
  @scope.find_in_batches do |batch|
    Supple.client.bulk({
      index: @index_name,
      type: @document_type,
      body: transform_batch(batch)
    })
  end
end

#transform_batch(batch) ⇒ Object (protected)



28
29
30
# File 'lib/supple/model.rb', line 28

def transform_batch(batch)
   batch.map { |a| { index: { _id: a.id, data: a.as_indexed_json } } }
end