class Elasticity::Search::ScanCursor

Public Class Methods

new(client, search_definition, mapper, size: 100, scroll: "1m") click to toggle source
# File lib/elasticity/search.rb, line 133
def initialize(client, search_definition, mapper, size: 100, scroll: "1m")
  @client            = client
  @search_definition = search_definition
  @mapper            = mapper
  @size              = size
  @scroll            = scroll
end

Public Instance Methods

blank?() click to toggle source
# File lib/elasticity/search.rb, line 145
def blank?
  empty?
end
each() { |doc| ... } click to toggle source
# File lib/elasticity/search.rb, line 164
def each
  enumerator.each do |group|
    group.each { |doc| yield(doc) }
  end
end
each_batch() { |group| ... } click to toggle source
# File lib/elasticity/search.rb, line 158
def each_batch
  enumerator.each do |group|
    yield(group)
  end
end
empty?() click to toggle source
# File lib/elasticity/search.rb, line 141
def empty?
  total == 0
end
total() click to toggle source
# File lib/elasticity/search.rb, line 149
def total
  res = search["hits"]["total"]
  if res.is_a?(::Hash)
    res["value"]
  else
    res
  end
end

Private Instance Methods

enumerator() click to toggle source
# File lib/elasticity/search.rb, line 172
def enumerator
  Enumerator.new do |y|
    response = search
    # Push the first set of results before requesting the second set
    y << Search::Results.new(response, @search_definition.body, @mapper)
    loop do
      response = @client.scroll(scroll_id: response["_scroll_id"], scroll: @scroll, body: { scroll_id: response["_scroll_id"] })
      break if response["hits"]["hits"].empty?

      y << Search::Results.new(response, @search_definition.body, @mapper)
    end
  end
end