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.



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

def initialize(klass, search, options={})
  @klass     = klass
  @search    = search
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



30
31
32
# File 'lib/elasticsearch/model/response.rb', line 30

def klass
  @klass
end

#searchObject (readonly)

Returns the value of attribute search.



30
31
32
# File 'lib/elasticsearch/model/response.rb', line 30

def search
  @search
end

Instance Method Details

#aggregationsObject

Returns a Hashie::Mash of the aggregations



85
86
87
# File 'lib/elasticsearch/model/response.rb', line 85

def aggregations
  @aggregations ||= Aggregations.new(raw_response['aggregations'])
end

#raw_responseObject



95
96
97
# File 'lib/elasticsearch/model/response.rb', line 95

def raw_response
  @raw_response ||= @response ? @response.to_hash : search.execute!
end

#records(options = {}) ⇒ Records

Returns the collection of records from the database

Returns:



61
62
63
# File 'lib/elasticsearch/model/response.rb', line 61

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

#responseHash

Returns the Elasticsearch response

Returns:

  • (Hash)


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

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

#resultsResults

Returns the collection of “hits” from Elasticsearch

Returns:



53
54
55
# File 'lib/elasticsearch/model/response.rb', line 53

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

#shardsObject

Returns the statistics on shards



79
80
81
# File 'lib/elasticsearch/model/response.rb', line 79

def shards
  @shards ||= response['_shards']
end

#suggestionsObject

Returns a Hashie::Mash of the suggestions



91
92
93
# File 'lib/elasticsearch/model/response.rb', line 91

def suggestions
  @suggestions ||= Suggestions.new(raw_response['suggest'])
end

#timed_outObject

Returns whether the response timed out



73
74
75
# File 'lib/elasticsearch/model/response.rb', line 73

def timed_out
  raw_response['timed_out']
end

#tookObject

Returns the “took” time



67
68
69
# File 'lib/elasticsearch/model/response.rb', line 67

def took
  raw_response['took']
end