Sha256: 069b0e116efb0664a072d5144ff9f679df6072e158e26aff5f96039ef4dc67b7

Contents?: true

Size: 702 Bytes

Versions: 1

Compression:

Stored size: 702 Bytes

Contents

# frozen_string_literal: true

module Elasticity
  class MultiSearchResponseParser
    class UnknownError < StandardError; end

    def self.parse(response, search)
      raise error_for(response["status"]), response.to_json if response["error"]

      case
      when search[:documents]
        Search::Results.new(response, search[:search_definition].body, search[:documents].method(:map_hit))
      when search[:active_records]
        Search::ActiveRecordProxy.map_response(search[:active_records], search[:search_definition].body, response)
      end
    end

    private

    def self.error_for(status)
      Elasticsearch::Transport::Transport::ERRORS[status] || UnknownError
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
es-elasticity-1.0.0.jhumphreys lib/elasticity/multi_search_response_parser.rb