Class: Elastictastic::MultiSearch
- Inherits:
-
Object
- Object
- Elastictastic::MultiSearch
- Defined in:
- lib/elastictastic/multi_search.rb
Defined Under Namespace
Classes: Component
Class Method Summary collapse
Instance Method Summary collapse
- #count(*scopes) ⇒ Object
-
#initialize ⇒ MultiSearch
constructor
A new instance of MultiSearch.
- #query(*scopes) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ MultiSearch
Returns a new instance of MultiSearch.
15 16 17 |
# File 'lib/elastictastic/multi_search.rb', line 15 def initialize @components = [] end |
Class Method Details
.count(*scopes) ⇒ Object
11 12 13 |
# File 'lib/elastictastic/multi_search.rb', line 11 def self.count(*scopes) new.count(*scopes).run end |
.query(*scopes) ⇒ Object
7 8 9 |
# File 'lib/elastictastic/multi_search.rb', line 7 def self.query(*scopes) new.query(*scopes).run end |
Instance Method Details
#count(*scopes) ⇒ Object
27 28 29 30 31 |
# File 'lib/elastictastic/multi_search.rb', line 27 def count(*scopes) components = scopes.flatten.map { |scope| Component.new(scope, 'count') } @components.concat(components) self end |
#query(*scopes) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/elastictastic/multi_search.rb', line 19 def query(*scopes) components = validate_scopes_for_query(scopes.flatten).map do |scope| Component.new(scope, 'query_then_fetch') end @components.concat(components) self end |
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/elastictastic/multi_search.rb', line 33 def run if @components.any? responses = Elastictastic.client.msearch(search_bodies)['responses'] responses.zip(@components) do |response, component| raise ServerError[response['error']] if response['error'] scope, search_type = component.scope, component.search_type case search_type when 'query_then_fetch' then scope.response = response when 'count' then scope.counts = response end end end self end |