README.md in elasticsearch-transport-1.0.0 vs README.md in elasticsearch-transport-1.0.1
- old
+ new
@@ -26,12 +26,13 @@
* Pluggable serializer implementation
* Request retries and dead connections handling
* Node reloading (based on cluster state) on errors or on demand
For optimal performance, you should use a HTTP library which supports persistent ("keep-alive") connections,
-e.g. [Typhoeus](https://github.com/typhoeus/typhoeus) or [Curb](https://github.com/taf2/curb/) --
-see example configurations [below](#transport-implementations).
+e.g. [Typhoeus](https://github.com/typhoeus/typhoeus) or [Patron](https://github.com/toland/patron).
+Just `require 'typhoeus'` or `require 'patron'` in your code, and it will be used.
+For detailed information, see example configurations [below](#transport-implementations).
## Installation
Install the package from [Rubygems](https://rubygems.org):
@@ -196,33 +197,65 @@
Elasticsearch::Client.new hosts: ['x1.search.org', 'x2.search.org'], selector_class: RackIdSelector
### Transport Implementations
By default, the client will use the [_Faraday_](https://rubygems.org/gems/faraday) HTTP library
-as a transport implementation. You can configure the _Faraday_ instance, eg. to use a different
-HTTP adapter (such as Typhoeus) or custom middleware, by passing a configuration block
-to the transport constructor:
+as a transport implementation.
+It will auto-detect and use an _adapter_ for _Faraday_ based on gems loaded in your code,
+preferring HTTP clients with support for persistent connections.
+
+To use the [_Patron_](https://github.com/toland/patron) HTTP, for example, just require it:
+
+ require 'patron'
+
+Then, create a new client, and the _Patron_ gem will be used as the "driver":
+
+ client = Elasticsearch::Client.new
+
+ client.transport.connections.first.connection.builder.handlers
+ # => [Faraday::Adapter::Patron]
+
+ 10.times do
+ client.nodes.stats(metric: 'http')['nodes'].values.each do |n|
+ puts "#{n['name']} : #{n['http']['total_opened']}"
+ end
+ end
+
+ # => Stiletoo : 24
+ # => Stiletoo : 24
+ # => Stiletoo : 24
+ # => ...
+
+To use a specific adapter for _Faraday_, pass it as the `adapter` argument:
+
+ 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'
- configuration = lambda do |f|
+ transport_configuration = lambda do |f|
f.response :logger
f.adapter :typhoeus
end
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
hosts: [ { host: 'localhost', port: '9200' } ],
- &configuration
+ &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:
+[`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: {
request: { open_timeout: 1 },
headers: { user_agent: 'MyApp' },
params: { :format => 'yaml' }
@@ -231,13 +264,15 @@
You can also use a bundled [_Curb_](https://rubygems.org/gems/curb) based transport implementation:
require 'curb'
require 'elasticsearch/transport/transport/http/curb'
- # Use Curb as the HTTP client
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' } ],
@@ -271,11 +306,10 @@
#
client.transport = faraday_client
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. All the arguments
-passed to client will be passed as the `:options` parameter to the transport constructor.
+and passing it to the client as the `transport_class` parameter -- or injecting it directly.
### Serializer Implementations
By default, the [MultiJSON](http://rubygems.org/gems/multi_json) library is used as the
serializer implementation, and it will pick up the "right" adapter based on gems available.