class Elasticsearch::Helpers::ScrollHelper
Elasticsearch
Client
Helper for the Scroll API
@see www.elastic.co/guide/en/elasticsearch/reference/current/scroll-api.html
Public Class Methods
Source
# 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
Create a ScrollHelper
@param [Elasticsearch::Client] client (Required) Instance of Elasticsearch
client to use. @param [String] index (Required) Index on which to perform the Bulk actions. @param [Hash] body Body parameters to re-use in every scroll request @param [Time] scroll Specify how long a consistent view of the index should be maintained for scrolled search
Public Instance Methods
Source
# 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
Clear Scroll and resets inner documents collection
Source
# File lib/elasticsearch/helpers/scroll_helper.rb, line 45 def each(&block) until (docs = results).empty? docs.each(&block) end clear end
Implementation of each
for Enumerable module inclusion
@yieldparam document [Hash] yields a document found in the search hits.
Source
# 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
Results from a scroll. Can be called repeatedly (e.g. in a loop) to get the scroll pages.
Private Instance Methods
Source
# File lib/elasticsearch/helpers/scroll_helper.rb, line 74 def initial_search response = @client.search(index: @index, scroll: @scroll, body: @body) @scroll_id = response['_scroll_id'] response['hits']['hits'] end
Source
# File lib/elasticsearch/helpers/scroll_helper.rb, line 80 def scroll_request @client.scroll(body: { scroll: @scroll, scroll_id: @scroll_id })['hits']['hits'] end