Class: ElasticRecord::Index::ScanSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_record/index/documents.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elastic_index, scroll_id, options = {}) ⇒ ScanSearch

Returns a new instance of ScanSearch.



9
10
11
12
13
# File 'lib/elastic_record/index/documents.rb', line 9

def initialize(elastic_index, scroll_id, options = {})
  @elastic_index  = elastic_index
  @scroll_id      = scroll_id
  @options        = options
end

Instance Attribute Details

#scroll_idObject (readonly)

Returns the value of attribute scroll_id.



6
7
8
# File 'lib/elastic_record/index/documents.rb', line 6

def scroll_id
  @scroll_id
end

#total_hitsObject

Returns the value of attribute total_hits.



7
8
9
# File 'lib/elastic_record/index/documents.rb', line 7

def total_hits
  @total_hits
end

Instance Method Details

#each_slice(&block) ⇒ Object



15
16
17
18
19
# File 'lib/elastic_record/index/documents.rb', line 15

def each_slice(&block)
  while (hit_ids = request_more_ids).any?
    hit_ids.each_slice(requested_batch_size, &block)
  end
end

#keep_aliveObject



33
34
35
# File 'lib/elastic_record/index/documents.rb', line 33

def keep_alive
  @options[:keep_alive] || (raise "Must provide a :keep_alive option")
end

#request_more_hitsObject



21
22
23
# File 'lib/elastic_record/index/documents.rb', line 21

def request_more_hits
  request_next_scroll['hits']['hits']
end

#request_more_idsObject



25
26
27
# File 'lib/elastic_record/index/documents.rb', line 25

def request_more_ids
  request_more_hits.map { |hit| hit['_id'] }
end

#request_next_scrollObject



29
30
31
# File 'lib/elastic_record/index/documents.rb', line 29

def request_next_scroll
  @elastic_index.scroll(@scroll_id, keep_alive)
end

#requested_batch_sizeObject



37
38
39
# File 'lib/elastic_record/index/documents.rb', line 37

def requested_batch_size
  @options[:batch_size]
end