Class: Elasticated::Repository::ScrollSearch
- Defined in:
- lib/elasticated/repository/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 40 41 |
# File 'lib/elasticated/repository/scroll_search.rb', line 11 def execute body = query.build_for_search size = scroll_page_size override! body response = client.search body, opts.merge(scroll: scroll_expiration_time, size: scroll_page_size) results = parse_and_prepare_results response, query results.append fetch_aggregations if aggregated target_size = query.limited? ? query._size : results.hits.total total_pages = (target_size / size.to_f).ceil current_page = 1 loop do break if current_page >= total_pages response = client.scroll results.scroll_id, scroll: scroll_expiration_time new_results = parse_and_prepare_results response hits = new_results.documents doc_count = results.documents.count new_results.documents = hits.first(target_size - doc_count) if query.limited? && (doc_count + hits.count > target_size) results.append new_results break if new_results.documents.count < size current_page += 1 end results end |
#fetch_aggregations ⇒ Object
5 6 7 8 9 |
# File 'lib/elasticated/repository/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 |