class Elasticsearch::Model::Response::Response

Encapsulate the response returned from the Elasticsearch client

Implements Enumerable and forwards its methods to the {#results} object.

Attributes

klass[R]

Public Class Methods

new(klass, search, options={}) click to toggle source
# File lib/elasticsearch/model/response.rb, line 36
def initialize(klass, search, options={})
  @klass     = klass
  @search    = search
end

Public Instance Methods

aggregations() click to toggle source

Returns a Hashie::Mash of the aggregations

# File lib/elasticsearch/model/response.rb, line 85
def aggregations
  @aggregations ||= Aggregations.new(raw_response['aggregations'])
end
raw_response() click to toggle source
# File lib/elasticsearch/model/response.rb, line 95
def raw_response
  @raw_response ||= @response ? @response.to_hash : search.execute!
end
records(options = {}) click to toggle source

Returns the collection of records from the database

@return [Records]

# File lib/elasticsearch/model/response.rb, line 61
def records(options = {})
  @records ||= Records.new(klass, self, options)
end
response() click to toggle source

Returns the Elasticsearch response

@return [Hash]

# File lib/elasticsearch/model/response.rb, line 45
def response
  @response ||= HashWrapper.new(search.execute!)
end
results() click to toggle source

Returns the collection of “hits” from Elasticsearch

@return [Results]

# File lib/elasticsearch/model/response.rb, line 53
def results
  @results ||= Results.new(klass, self)
end
shards() click to toggle source

Returns the statistics on shards

# File lib/elasticsearch/model/response.rb, line 79
def shards
  @shards ||= response['_shards']
end
suggestions() click to toggle source

Returns a Hashie::Mash of the suggestions

# File lib/elasticsearch/model/response.rb, line 91
def suggestions
  @suggestions ||= Suggestions.new(raw_response['suggest'])
end
timed_out() click to toggle source

Returns whether the response timed out

# File lib/elasticsearch/model/response.rb, line 73
def timed_out
  raw_response['timed_out']
end
took() click to toggle source

Returns the “took” time

# File lib/elasticsearch/model/response.rb, line 67
def took
  raw_response['took']
end