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.



7
8
9
# File 'lib/elasticsearch/model/response/base.rb', line 7

def klass
  @klass
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/elasticsearch/model/response/base.rb', line 7

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



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

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

#max_scoreObject

Returns the max_score



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

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

#recordsObject

This method is abstract.

Implement this method in specific class

Raises:



26
27
28
# File 'lib/elasticsearch/model/response/base.rb', line 26

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

#resultsObject

This method is abstract.

Implement this method in specific class

Raises:



20
21
22
# File 'lib/elasticsearch/model/response/base.rb', line 20

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

#totalObject

Returns the total number of hits



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

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