Module: Elasticsearch::Model::Response::Base

Included in:
Records, Results
Defined in:
lib/elasticsearch/model/response/base.rb

Overview

Common funtionality for classes in the Elasticsearch::Model::Response module

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



24
25
26
# File 'lib/elasticsearch/model/response/base.rb', line 24

def klass
  @klass
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



24
25
26
# File 'lib/elasticsearch/model/response/base.rb', line 24

def raw_response
  @raw_response
end

#responseObject (readonly)

Returns the value of attribute response.



24
25
26
# File 'lib/elasticsearch/model/response/base.rb', line 24

def response
  @response
end

Instance Method Details

#initialize(klass, response, options = {}) ⇒ Object

Parameters:

  • klass (Class)

    The name of the model class

  • response (Hash)

    The full response returned from Elasticsearch client

  • options (Hash) (defaults to: {})

    Optional parameters



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

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

#max_scoreObject

Returns the max_score



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

def max_score
  response.response['hits']['max_score']
end

#recordsObject

This method is abstract.

Implement this method in specific class

Raises:



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

def records
  raise NotImplemented, "Implement this method in #{klass}"
end

#resultsObject

This method is abstract.

Implement this method in specific class

Raises:



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

def results
  raise NotImplemented, "Implement this method in #{klass}"
end

#totalObject

Returns the total number of hits



50
51
52
53
54
55
56
# File 'lib/elasticsearch/model/response/base.rb', line 50

def total
  if response.response['hits']['total'].respond_to?(:keys)
    response.response['hits']['total']['value']
  else
    response.response['hits']['total']
  end
end