Class: JayAPI::Elasticsearch::Response

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.

Parameters:

  • raw_response (Hash)

    The raw results data from Elasticsearch



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_responseObject (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

#aggregationsHash?

Returns The aggregations present in the current result set (if there are any).

Returns:

  • (Hash, nil)

    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

#hitsArray<Hash>

The actual “hits” results from the Elasticsearch response

Returns:

  • (Array<Hash>)


32
33
34
# File 'lib/jay_api/elasticsearch/response.rb', line 32

def hits
  @hits ||= raw_response.dig('hits', 'hits') || []
end

#totalInteger

The total count of results that match the query criteria

Returns:

  • (Integer)


38
39
40
# File 'lib/jay_api/elasticsearch/response.rb', line 38

def total
  @total ||= raw_response.dig('hits', 'total', 'value') || hits.size
end