Class: ElasticSearch::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_search/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/elastic_search/response.rb', line 5

def initialize(options)
  @body = options[:body].eql?("") ? "{}" : options[:body]
  @status = options[:status].to_i

  case @status
  when 200..206
  when 404
    if self.body['error'] =~ /^IndexMissingException/ || self.body.eql?(nil)
      raise ElasticSearch::IndexMissingException, "#{self.body['status']}: #{self.body['error']}"
    elsif self.body['exists'].eql?(false)
      raise ElasticSearch::ItemMissingException, "_id: #{self.body['id']} NOT FOUND"
    else
      raise ElasticSearch::NotFoundError
    end
  else
    raise ElasticSearch::ResponseError, "#{self.body['status']}: #{self.body['error']}"
  end
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/elastic_search/response.rb', line 3

def status
  @status
end

Instance Method Details

#bodyObject



24
25
26
# File 'lib/elastic_search/response.rb', line 24

def body
  @decoded_body ||= (@body ? ActiveSupport::JSON.decode(@body) : {})
end