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
71 72 73 74 |
# File 'lib/elasticsearch/helpers/scroll_helper.rb', line 71 def clear @client.clear_scroll(body: { scroll_id: @scroll_id }) if @scroll_id @docs = [] end |
#each {|document| ... } ⇒ Object
Implementation of each
for Enumerable module inclusion
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elasticsearch/helpers/scroll_helper.rb', line 45 def each(&block) @docs = [] @scroll_id = nil refresh_docs for doc in @docs do refresh_docs yield doc end clear end |
#results ⇒ Object
Results from a scroll. Can be called repeatedly (e.g. in a loop) to get the scroll pages.
59 60 61 62 63 64 65 66 67 |
# File 'lib/elasticsearch/helpers/scroll_helper.rb', line 59 def results if @scroll_id scroll_request else initial_search end rescue StandardError => e raise e end |