module Elasticsearch::Rails2::Searching::ClassMethods

Public Instance Methods

scan_all_ids(query_or_payload, options={}) click to toggle source

Scan and scroll all ids Useful to do a SQL query with IN(…) operator

# File lib/elasticsearch/rails2/searching.rb, line 106
def scan_all_ids(query_or_payload, options={})
  ids = []
  scroll = options[:scroll]
  search_response = search(query_or_payload, options.update(search_type: 'scan'))
  response = search_response.response
  while response = client.scroll(scroll_id: response['_scroll_id'], scroll: scroll) and !response['hits']['hits'].empty? do
    response['hits']['hits'].each { |r| ids << r['_id']}
  end
  ids
end