Class: Scalastic::Scroller
- Inherits:
-
Object
- Object
- Scalastic::Scroller
- Includes:
- Enumerable
- Defined in:
- lib/scalastic/scroller.rb
Instance Attribute Summary collapse
-
#scroll ⇒ Object
Returns the value of attribute scroll.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(es_client, args) ⇒ Scroller
constructor
A new instance of Scroller.
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
#scroll ⇒ Object
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 |