Class: Scalastic::Scroller

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/scalastic/scroller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(es_client, args) ⇒ Scroller

Returns a new instance of Scroller.



5
6
7
8
9
# File 'lib/scalastic/scroller.rb', line 5

def initialize(es_client, args)
  @es_client = es_client
  @args = args
  @scroll = '1m'
end

Instance Attribute Details

#scrollObject

Returns the value of attribute scroll.



16
17
18
# File 'lib/scalastic/scroller.rb', line 16

def scroll
  @scroll
end

Instance Method Details

#each(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/scalastic/scroller.rb', line 18

def each(&block)
  Enumerator.new do |enum|
    args = @args.merge(search_type: 'scan', scroll: scroll)
    res = @es_client.search(args)
    loop do
      scroll_id = res['_scroll_id']
      res = @es_client.scroll(body: scroll_id, scroll: scroll)
      hits = res['hits']['hits']
      break unless hits.any?
      hits.each{|h| enum << h}
    end
  end.each(&block)
end