Class: Elasticated::Repository::ScanScrollSearch
- Defined in:
- lib/elasticated/repository/scan_scroll_search.rb
Instance Attribute Summary
Attributes inherited from Search
#aggregated, #opts, #query, #repository
Instance Method Summary collapse
Methods inherited from Search
Constructor Details
This class inherits a constructor from Elasticated::Repository::Search
Instance Method Details
#execute ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/elasticated/repository/scan_scroll_search.rb', line 11 def execute # aggregations results = nil if aggregated body = query.build_for_aggregations response = client.search body, opts results = parse_and_prepare_results response, query end # search body = query.build_for_search response = client.search body, opts.merge(search_type: 'scan', scroll: scroll_expiration_time, size: scroll_page_size) results = parse_and_prepare_results response results.append fetch_aggregations if aggregated doc_count = 0 loop do response = client.scroll results.scroll_id, scroll: scroll_expiration_time new_results = parse_and_prepare_results response hits = new_results.documents break if hits.empty? if query.limited? && (doc_count + hits.count > query._size) new_results.documents = hits.first(query._size - doc_count) hits = new_results.documents end doc_count += hits.count results = results.append new_results break if query.limited? && doc_count >= query._size end results end |
#fetch_aggregations ⇒ Object
5 6 7 8 9 |
# File 'lib/elasticated/repository/scan_scroll_search.rb', line 5 def fetch_aggregations body = query.build_for_aggregations response = client.search body, opts parse_and_prepare_results response, query end |