README.md in elasticsearch-transport-1.0.14 vs README.md in elasticsearch-transport-1.0.15
- old
+ new
@@ -269,28 +269,10 @@
client = Elasticsearch::Client.new adapter: :net_http_persistent
client.transport.connections.first.connection.builder.handlers
# => [Faraday::Adapter::NetHttpPersistent]
-To configure the _Faraday_ instance, pass a configuration block to the transport constructor:
-
- require 'typhoeus'
- require 'typhoeus/adapters/faraday'
-
- transport_configuration = lambda do |f|
- f.response :logger
- f.adapter :typhoeus
- end
-
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
- hosts: [ { host: 'localhost', port: '9200' } ],
- &transport_configuration
-
- # Pass the transport to the client
- #
- client = Elasticsearch::Client.new transport: transport
-
To pass options to the
[`Faraday::Connection`](https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb)
constructor, use the `transport_options` key:
client = Elasticsearch::Client.new transport_options: {
@@ -298,27 +280,50 @@
headers: { user_agent: 'MyApp' },
params: { :format => 'yaml' },
ssl: { verify: false }
}
-You can also use a bundled [_Curb_](https://rubygems.org/gems/curb) based transport implementation:
+To configure the _Faraday_ instance directly, use a block:
- require 'curb'
- require 'elasticsearch/transport/transport/http/curb'
+ require 'typhoeus'
+ require 'typhoeus/adapters/faraday'
- client = Elasticsearch::Client.new transport_class: Elasticsearch::Transport::Transport::HTTP::Curb
+ client = Elasticsearch::Client.new(host: 'localhost', port: '9200') do |f|
+ f.response :logger
+ f.adapter :typhoeus
+ end
- client.transport.connections.first.connection
- # => #<Curl::Easy http://localhost:9200/>
+You can use any standard Faraday middleware and plugins in the configuration block,
+for example sign the requests for the [AWS Elasticsearch service](https://aws.amazon.com/elasticsearch-service/):
-It's possible to customize the _Curb_ instance by passing a block to the constructor as well
-(in this case, as an inline block):
+ require 'patron'
+ require 'faraday_middleware/aws_signers_v4'
- transport = Elasticsearch::Transport::Transport::HTTP::Curb.new \
+ client = Elasticsearch::Client.new url: 'https://search-my-cluster-abc123....es.amazonaws.com' do |f|
+ f.request :aws_signers_v4,
+ credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET_ACCESS_KEY']),
+ service_name: 'es',
+ region: 'us-east-1'
+ end
+
+You can also initialize the transport class yourself, and pass it to the client constructor
+as the `transport` argument:
+
+ require 'typhoeus'
+ require 'typhoeus/adapters/faraday'
+
+ transport_configuration = lambda do |f|
+ f.response :logger
+ f.adapter :typhoeus
+ end
+
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
hosts: [ { host: 'localhost', port: '9200' } ],
- & lambda { |c| c.verbose = true }
+ &transport_configuration
+ # Pass the transport to the client
+ #
client = Elasticsearch::Client.new transport: transport
Instead of passing the transport to the constructor, you can inject it at run time:
# Set up the transport
@@ -342,9 +347,28 @@
client = Elasticsearch::Client.new
# Inject the transport to the client
#
client.transport = faraday_client
+
+You can also use a bundled [_Curb_](https://rubygems.org/gems/curb) based transport implementation:
+
+ require 'curb'
+ require 'elasticsearch/transport/transport/http/curb'
+
+ client = Elasticsearch::Client.new transport_class: Elasticsearch::Transport::Transport::HTTP::Curb
+
+ client.transport.connections.first.connection
+ # => #<Curl::Easy http://localhost:9200/>
+
+It's possible to customize the _Curb_ instance by passing a block to the constructor as well
+(in this case, as an inline block):
+
+ transport = Elasticsearch::Transport::Transport::HTTP::Curb.new \
+ hosts: [ { host: 'localhost', port: '9200' } ],
+ & lambda { |c| c.verbose = true }
+
+ client = Elasticsearch::Client.new transport: transport
You can write your own transport implementation easily, by including the
{Elasticsearch::Transport::Transport::Base} module, implementing the required contract,
and passing it to the client as the `transport_class` parameter -- or injecting it directly.