lib/elasticsearch/model/response.rb in elasticsearch-model-6.0.0.pre vs lib/elasticsearch/model/response.rb in elasticsearch-model-6.0.0

- old
+ new

@@ -8,12 +8,11 @@ # Encapsulate the response returned from the Elasticsearch client # # Implements Enumerable and forwards its methods to the {#results} object. # class Response - attr_reader :klass, :search, :response, - :took, :timed_out, :shards + attr_reader :klass, :search include Enumerable delegate :each, :empty?, :size, :slice, :[], :to_ary, to: :results @@ -25,13 +24,11 @@ # Returns the Elasticsearch response # # @return [Hash] # def response - @response ||= begin - HashWrapper.new(search.execute!) - end + @response ||= HashWrapper.new(search.execute!) end # Returns the collection of "hits" from Elasticsearch # # @return [Results] @@ -49,34 +46,38 @@ end # Returns the "took" time # def took - response['took'] + raw_response['took'] end # Returns whether the response timed out # def timed_out - response['timed_out'] + raw_response['timed_out'] end # Returns the statistics on shards # def shards - HashWrapper.new(response['_shards']) + @shards ||= HashWrapper.new(raw_response['_shards']) end # Returns a Hashie::Mash of the aggregations # def aggregations - Aggregations.new(response['aggregations']) + @aggregations ||= Aggregations.new(raw_response['aggregations']) end # Returns a Hashie::Mash of the suggestions # def suggestions - Suggestions.new(response['suggest']) + @suggestions ||= Suggestions.new(raw_response['suggest']) + end + + def raw_response + @raw_response ||= search.execute! end end end end end