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.
19 20 21 22 |
# File 'lib/elasticsearch/model/response.rb', line 19 def initialize(klass, search, ={}) @klass = klass @search = search end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
13 14 15 |
# File 'lib/elasticsearch/model/response.rb', line 13 def klass @klass end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
13 14 15 |
# File 'lib/elasticsearch/model/response.rb', line 13 def search @search end |
Instance Method Details
#aggregations ⇒ Object
Returns a Hashie::Mash of the aggregations
68 69 70 |
# File 'lib/elasticsearch/model/response.rb', line 68 def aggregations @aggregations ||= Aggregations.new(raw_response['aggregations']) end |
#raw_response ⇒ Object
78 79 80 |
# File 'lib/elasticsearch/model/response.rb', line 78 def raw_response @raw_response ||= search.execute! end |
#records(options = {}) ⇒ Records
Returns the collection of records from the database
44 45 46 |
# File 'lib/elasticsearch/model/response.rb', line 44 def records( = {}) @records ||= Records.new(klass, self, ) end |
#response ⇒ Hash
Returns the Elasticsearch response
28 29 30 |
# File 'lib/elasticsearch/model/response.rb', line 28 def response @response ||= HashWrapper.new(search.execute!) end |
#results ⇒ Results
Returns the collection of “hits” from Elasticsearch
36 37 38 |
# File 'lib/elasticsearch/model/response.rb', line 36 def results @results ||= Results.new(klass, self) end |
#shards ⇒ Object
Returns the statistics on shards
62 63 64 |
# File 'lib/elasticsearch/model/response.rb', line 62 def shards @shards ||= HashWrapper.new(raw_response['_shards']) end |
#suggestions ⇒ Object
Returns a Hashie::Mash of the suggestions
74 75 76 |
# File 'lib/elasticsearch/model/response.rb', line 74 def suggestions @suggestions ||= Suggestions.new(raw_response['suggest']) end |
#timed_out ⇒ Object
Returns whether the response timed out
56 57 58 |
# File 'lib/elasticsearch/model/response.rb', line 56 def timed_out raw_response['timed_out'] end |
#took ⇒ Object
Returns the “took” time
50 51 52 |
# File 'lib/elasticsearch/model/response.rb', line 50 def took raw_response['took'] end |