Class: JayAPI::Elasticsearch::Response
- Inherits:
-
Object
- Object
- JayAPI::Elasticsearch::Response
- Extended by:
- Forwardable
- Defined in:
- lib/jay_api/elasticsearch/response.rb
Overview
The ‘Response` class encapsulates and processes the results received from an Elasticsearch query. It provides a uniform interface for accessing and working with the retrieved data.
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Instance Method Summary collapse
-
#aggregations ⇒ Hash?
The aggregations present in the current result set (if there are any).
-
#hits ⇒ Array<Hash>
The actual “hits” results from the Elasticsearch response.
-
#initialize(raw_response) ⇒ Response
constructor
A new instance of Response.
-
#total ⇒ Integer
The total count of results that match the query criteria.
Constructor Details
#initialize(raw_response) ⇒ Response
Returns a new instance of Response.
20 21 22 |
# File 'lib/jay_api/elasticsearch/response.rb', line 20 def initialize(raw_response) @raw_response = raw_response end |
Instance Attribute Details
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
15 16 17 |
# File 'lib/jay_api/elasticsearch/response.rb', line 15 def raw_response @raw_response end |
Instance Method Details
#aggregations ⇒ Hash?
Returns The aggregations present in the current result set (if there are any).
26 27 28 |
# File 'lib/jay_api/elasticsearch/response.rb', line 26 def aggregations @aggregations ||= raw_response['aggregations'] end |
#hits ⇒ Array<Hash>
The actual “hits” results from the Elasticsearch response
32 33 34 |
# File 'lib/jay_api/elasticsearch/response.rb', line 32 def hits @hits ||= raw_response.dig('hits', 'hits') || [] end |
#total ⇒ Integer
The total count of results that match the query criteria
38 39 40 |
# File 'lib/jay_api/elasticsearch/response.rb', line 38 def total @total ||= raw_response.dig('hits', 'total', 'value') || hits.size end |