Class: Elasticsearch::Transport::Client
- Inherits:
-
Object
- Object
- Elasticsearch::Transport::Client
- Defined in:
- lib/elasticsearch/transport/client.rb
Overview
Handles communication with an Elasticsearch cluster.
See README for usage and code examples.
Constant Summary collapse
- DEFAULT_TRANSPORT_CLASS =
Transport::HTTP::Faraday
- DEFAULT_LOGGER =
lambda do require 'logger' logger = Logger.new(STDERR) logger.progname = 'elasticsearch' logger.formatter = proc { |severity, datetime, progname, msg| "#{datetime}: #{msg}\n" } logger end
- DEFAULT_TRACER =
lambda do require 'logger' logger = Logger.new(STDERR) logger.progname = 'elasticsearch.tracer' logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" } logger end
- DEFAULT_HOST =
The default host and port to use if not otherwise specified.
'localhost:9200'.freeze
- DEFAULT_CLOUD_PORT =
The default port to use if connecting using a Cloud ID.
9243
Instance Attribute Summary collapse
-
#transport ⇒ Object
Returns the transport object.
Instance Method Summary collapse
-
#initialize(arguments = {}) {|faraday| ... } ⇒ Client
constructor
Create a client connected to an Elasticsearch cluster.
-
#perform_request(method, path, params = {}, body = nil, headers = nil) ⇒ Object
Performs a request through delegation to #transport.
Constructor Details
#initialize(arguments = {}) {|faraday| ... } ⇒ Client
Create a client connected to an Elasticsearch cluster.
Specify the URL via arguments or set the ‘ELASTICSEARCH_URL` environment variable.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/elasticsearch/transport/client.rb', line 104 def initialize(arguments={}, &block) @options = arguments.each_with_object({}){ |(k,v), args| args[k.to_sym] = v } @arguments = @options @arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call() : nil @arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call() : nil @arguments[:reload_connections] ||= false @arguments[:retry_on_failure] ||= false @arguments[:reload_on_failure] ||= false @arguments[:randomize_hosts] ||= false @arguments[:transport_options] ||= {} @arguments[:http] ||= {} @options[:http] ||= {} @seeds = extract_cloud_creds(@arguments) @seeds ||= __extract_hosts(@arguments[:hosts] || @arguments[:host] || @arguments[:url] || @arguments[:urls] || ENV['ELASTICSEARCH_URL'] || DEFAULT_HOST) @send_get_body_as = @arguments[:send_get_body_as] || 'GET' if @arguments[:request_timeout] @arguments[:transport_options][:request] = { :timeout => @arguments[:request_timeout] } end if @arguments[:transport] @transport = @arguments[:transport] else transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS if transport_class == Transport::HTTP::Faraday @transport = transport_class.new(:hosts => @seeds, :options => @arguments) do |faraday| block.call faraday if block unless (h = faraday.builder.handlers.last) && h.name.start_with?("Faraday::Adapter") faraday.adapter(@arguments[:adapter] || __auto_detect_adapter) end end else @transport = transport_class.new(:hosts => @seeds, :options => @arguments) end end end |
Instance Attribute Details
#transport ⇒ Object
Returns the transport object.
48 49 50 |
# File 'lib/elasticsearch/transport/client.rb', line 48 def transport @transport end |
Instance Method Details
#perform_request(method, path, params = {}, body = nil, headers = nil) ⇒ Object
Performs a request through delegation to #transport.
150 151 152 153 |
# File 'lib/elasticsearch/transport/client.rb', line 150 def perform_request(method, path, params={}, body=nil, headers=nil) method = @send_get_body_as if 'GET' == method && body transport.perform_request(method, path, params, body, headers) end |