Class: Elasticsearch::Helpers::ScrollHelper
- Inherits:
-
Object
- Object
- Elasticsearch::Helpers::ScrollHelper
- Includes:
- Enumerable
- Defined in:
- lib/elasticsearch/helpers/scroll_helper.rb
Overview
Elasticsearch Client Helper for the Scroll API
Instance Method Summary collapse
-
#clear ⇒ Object
Clear Scroll and resets inner documents collection.
-
#each {|document| ... } ⇒ Object
Implementation of
each
for Enumerable module inclusion. -
#initialize(client, index, body, scroll = '1m') ⇒ ScrollHelper
constructor
Create a ScrollHelper.
-
#results ⇒ Object
Results from a scroll.
Constructor Details
#initialize(client, index, body, scroll = '1m') ⇒ ScrollHelper
Create a ScrollHelper
34 35 36 37 38 39 |
# File 'lib/elasticsearch/helpers/scroll_helper.rb', line 34 def initialize(client, index, body, scroll = '1m') @index = index @client = client @scroll = scroll @body = body end |
Instance Method Details
#clear ⇒ Object
Clear Scroll and resets inner documents collection
67 68 69 70 |
# File 'lib/elasticsearch/helpers/scroll_helper.rb', line 67 def clear @client.clear_scroll(body: { scroll_id: @scroll_id }) if @scroll_id @scroll_id = nil end |
#each {|document| ... } ⇒ Object
Implementation of each
for Enumerable module inclusion
45 46 47 48 49 50 |
# File 'lib/elasticsearch/helpers/scroll_helper.rb', line 45 def each(&block) until (docs = results).empty? docs.each(&block) end clear end |
#results ⇒ Object
Results from a scroll. Can be called repeatedly (e.g. in a loop) to get the scroll pages.
55 56 57 58 59 60 61 62 63 |
# File 'lib/elasticsearch/helpers/scroll_helper.rb', line 55 def results if @scroll_id scroll_request else initial_search end rescue StandardError => e raise e end |