Class: Elasticsearch::Model::Searching::SearchRequest
- Inherits:
- 
      Object
      
        - Object
- Elasticsearch::Model::Searching::SearchRequest
 
- Defined in:
- lib/elasticsearch/model/searching.rb
Overview
Wraps a search request definition
Instance Attribute Summary collapse
- 
  
    
      #definition  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute definition. 
- 
  
    
      #klass  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute klass. 
Instance Method Summary collapse
- 
  
    
      #execute!  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    Performs the request and returns the response from client. 
- 
  
    
      #initialize(klass, query_or_payload, options = {})  ⇒ SearchRequest 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of SearchRequest. 
Constructor Details
#initialize(klass, query_or_payload, options = {}) ⇒ SearchRequest
Returns a new instance of SearchRequest.
| 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # File 'lib/elasticsearch/model/searching.rb', line 18 def initialize(klass, query_or_payload, ={}) @klass = klass __index_name = [:index] || klass.index_name __document_type = [:type] || klass.document_type case # search query: ... when query_or_payload.respond_to?(:to_hash) body = query_or_payload.to_hash # search '{ "query" : ... }' when query_or_payload.is_a?(String) && query_or_payload =~ /^\s*{/ body = query_or_payload # search '...' else q = query_or_payload end if body @definition = { index: __index_name, type: __document_type, body: body }.update else @definition = { index: __index_name, type: __document_type, q: q }.update end end | 
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
| 11 12 13 | # File 'lib/elasticsearch/model/searching.rb', line 11 def definition @definition end | 
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
| 11 12 13 | # File 'lib/elasticsearch/model/searching.rb', line 11 def klass @klass end | 
Instance Method Details
#execute! ⇒ Hash
Performs the request and returns the response from client
| 49 50 51 | # File 'lib/elasticsearch/model/searching.rb', line 49 def execute! klass.client.search(@definition) end |