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.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/elasticsearch/model/searching.rb', line 35 def initialize(klass, query_or_payload, ={}) @klass = klass @options = __index_name = [:index] || klass.index_name 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, body: body }.update else @definition = { index: __index_name, q: q }.update end end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
28 29 30 |
# File 'lib/elasticsearch/model/searching.rb', line 28 def definition @definition end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
28 29 30 |
# File 'lib/elasticsearch/model/searching.rb', line 28 def klass @klass end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
28 29 30 |
# File 'lib/elasticsearch/model/searching.rb', line 28 def @options end |
Instance Method Details
#execute! ⇒ Hash
Performs the request and returns the response from client
66 67 68 |
# File 'lib/elasticsearch/model/searching.rb', line 66 def execute! klass.client.search(@definition) end |