Class: ElasticRecord::Index::ScanSearch
- Inherits:
-
Object
- Object
- ElasticRecord::Index::ScanSearch
- Defined in:
- lib/elastic_record/index/documents.rb
Instance Attribute Summary collapse
-
#scroll_id ⇒ Object
readonly
Returns the value of attribute scroll_id.
-
#total_hits ⇒ Object
Returns the value of attribute total_hits.
Instance Method Summary collapse
- #each_slice(&block) ⇒ Object
-
#initialize(elastic_index, scroll_id, options = {}) ⇒ ScanSearch
constructor
A new instance of ScanSearch.
- #keep_alive ⇒ Object
- #request_more_hits ⇒ Object
- #request_more_ids ⇒ Object
- #request_next_scroll ⇒ Object
- #requested_batch_size ⇒ Object
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, = {}) @elastic_index = elastic_index @scroll_id = scroll_id @options = end |
Instance Attribute Details
#scroll_id ⇒ Object (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_hits ⇒ Object
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_alive ⇒ Object
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_hits ⇒ Object
21 22 23 |
# File 'lib/elastic_record/index/documents.rb', line 21 def request_more_hits request_next_scroll['hits']['hits'] end |
#request_more_ids ⇒ Object
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_scroll ⇒ Object
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_size ⇒ Object
37 38 39 |
# File 'lib/elastic_record/index/documents.rb', line 37 def requested_batch_size @options[:batch_size] end |