Class: Elastictastic::MultiGet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/elastictastic/multi_get.rb

Instance Method Summary collapse

Constructor Details

#initializeMultiGet

Returns a new instance of MultiGet.


7
8
9
10
# File 'lib/elastictastic/multi_get.rb', line 7

def initialize
  @docspecs = []
  @scopes = []
end

Instance Method Details

#add(scope, *ids) ⇒ Object


12
13
14
15
16
17
18
19
# File 'lib/elastictastic/multi_get.rb', line 12

def add(scope, *ids)
  scope = scope.all
  params = scope.multi_get_params
  ids.flatten.each do |id|
    @docspecs << params.merge('_id' => id.to_s)
    @scopes << scope
  end
end

#eachObject


21
22
23
24
25
26
# File 'lib/elastictastic/multi_get.rb', line 21

def each
  return if @docspecs.empty?
  Elastictastic.client.mget(@docspecs)['docs'].zip(@scopes) do |hit, scope|
    yield scope.materialize_hit(hit) if hit['exists']
  end
end