Class: Elasticsearch::Model::Response::Response

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

Instance Method Summary collapse

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, options={})
  @klass     = klass
  @search    = search
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



13
14
15
# File 'lib/elasticsearch/model/response.rb', line 13

def klass
  @klass
end

#searchObject (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

#aggregationsObject

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_responseObject



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

Returns:



44
45
46
# File 'lib/elasticsearch/model/response.rb', line 44

def records(options = {})
  @records ||= Records.new(klass, self, options)
end

#responseHash

Returns the Elasticsearch response

Returns:

  • (Hash)


28
29
30
# File 'lib/elasticsearch/model/response.rb', line 28

def response
  @response ||= HashWrapper.new(search.execute!)
end

#resultsResults

Returns the collection of “hits” from Elasticsearch

Returns:



36
37
38
# File 'lib/elasticsearch/model/response.rb', line 36

def results
  @results ||= Results.new(klass, self)
end

#shardsObject

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

#suggestionsObject

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_outObject

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

#tookObject

Returns the “took” time



50
51
52
# File 'lib/elasticsearch/model/response.rb', line 50

def took
  raw_response['took']
end