Class: Elasticsearch::Model::Response::Response
- Inherits:
-
Object
- Object
- Elasticsearch::Model::Response::Response
- Includes:
- Enumerable
- Defined in:
- lib/elasticsearch/model/response.rb
Overview
Encapsulate the response returned from the Elasticsearch client
Implements Enumerable and forwards its methods to the #results object.
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
Instance Method Summary collapse
-
#aggregations ⇒ Object
Returns a Hashie::Mash of the aggregations.
-
#initialize(klass, search, options = {}) ⇒ Response
constructor
A new instance of Response.
- #raw_response ⇒ Object
-
#records(options = {}) ⇒ Records
Returns the collection of records from the database.
-
#response ⇒ Hash
Returns the Elasticsearch response.
-
#results ⇒ Results
Returns the collection of “hits” from Elasticsearch.
-
#shards ⇒ Object
Returns the statistics on shards.
-
#suggestions ⇒ Object
Returns a Hashie::Mash of the suggestions.
-
#timed_out ⇒ Object
Returns whether the response timed out.
-
#took ⇒ Object
Returns the “took” time.
Constructor Details
#initialize(klass, search, options = {}) ⇒ Response
Returns a new instance of Response.
36 37 38 39 |
# File 'lib/elasticsearch/model/response.rb', line 36 def initialize(klass, search, ={}) @klass = klass @search = search end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
30 31 32 |
# File 'lib/elasticsearch/model/response.rb', line 30 def klass @klass end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
30 31 32 |
# File 'lib/elasticsearch/model/response.rb', line 30 def search @search end |
Instance Method Details
#aggregations ⇒ Object
Returns a Hashie::Mash of the aggregations
85 86 87 |
# File 'lib/elasticsearch/model/response.rb', line 85 def aggregations @aggregations ||= Aggregations.new(raw_response['aggregations']) end |
#raw_response ⇒ Object
95 96 97 |
# File 'lib/elasticsearch/model/response.rb', line 95 def raw_response @raw_response ||= @response ? @response.to_hash : search.execute! end |
#records(options = {}) ⇒ Records
Returns the collection of records from the database
61 62 63 |
# File 'lib/elasticsearch/model/response.rb', line 61 def records( = {}) @records ||= Records.new(klass, self, ) end |
#response ⇒ Hash
Returns the Elasticsearch response
45 46 47 |
# File 'lib/elasticsearch/model/response.rb', line 45 def response @response ||= HashWrapper.new(search.execute!) end |
#results ⇒ Results
Returns the collection of “hits” from Elasticsearch
53 54 55 |
# File 'lib/elasticsearch/model/response.rb', line 53 def results @results ||= Results.new(klass, self) end |
#shards ⇒ Object
Returns the statistics on shards
79 80 81 |
# File 'lib/elasticsearch/model/response.rb', line 79 def shards @shards ||= response['_shards'] end |
#suggestions ⇒ Object
Returns a Hashie::Mash of the suggestions
91 92 93 |
# File 'lib/elasticsearch/model/response.rb', line 91 def suggestions @suggestions ||= Suggestions.new(raw_response['suggest']) end |
#timed_out ⇒ Object
Returns whether the response timed out
73 74 75 |
# File 'lib/elasticsearch/model/response.rb', line 73 def timed_out raw_response['timed_out'] end |
#took ⇒ Object
Returns the “took” time
67 68 69 |
# File 'lib/elasticsearch/model/response.rb', line 67 def took raw_response['took'] end |