Skip to content

Commit 0796ff5

Browse files
committed
[DOCS] Updates documentation for Transport
1 parent 24855e9 commit 0796ff5

File tree

2 files changed

+74
-111
lines changed

2 files changed

+74
-111
lines changed

docs/overview.asciidoc

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
[[ruby_client]]
22
== Overview
33

4-
The `elasticsearch` http://rubygems.org/gems/elasticsearch[Rubygem] provides a
5-
low-level client for communicating with an {es} cluster, fully compatible with
6-
other official clients.
4+
The `elasticsearch` http://rubygems.org/gems/elasticsearch[Rubygem] provides a low-level client for communicating with an {es} cluster, fully compatible with other official clients.
75

86
More documentation is hosted in https://github.com/elastic/elasticsearch-ruby[Github] and http://rubydoc.info/gems/elasticsearch[RubyDoc].
97

@@ -26,18 +24,14 @@ More documentation is hosted in https://github.com/elastic/elasticsearch-ruby[Gi
2624

2725
The `elasticsearch` gem combines two separate Rubygems:
2826

29-
* https://github.com/elastic/elasticsearch-ruby/tree/main/elasticsearch-transport[`elasticsearch-transport`]
30-
provides an HTTP Ruby client for connecting to the {es} cluster,
27+
* https://github.com/elastic/elastic-transport-ruby/[`elastic-transport`]
28+
provides an HTTP Ruby client for connecting to the {es} cluster.
3129

3230
* https://github.com/elastic/elasticsearch-ruby/tree/main/elasticsearch-api[`elasticsearch-api`]
3331
provides a Ruby API for the {es} RESTful API.
3432

35-
Please consult their respective documentation for configuration options and
36-
technical details.
33+
Please consult their respective documentation for configuration options and technical details.
3734

38-
Notably, the documentation and comprehensive examples for all the API methods
39-
are contained in the source, and available online at
40-
http://rubydoc.info/gems/elasticsearch-api/Elasticsearch/API/Actions[Rubydoc].
35+
Notably, the documentation and comprehensive examples for all the API methods are contained in the source, and available online at http://rubydoc.info/gems/elasticsearch-api/Elasticsearch/API/Actions[Rubydoc].
4136

42-
Keep in mind, that for optimal performance, you should use an HTTP library which
43-
supports persistent ("keep-alive") HTTP connections.
37+
Keep in mind, that for optimal performance, you should use an HTTP library which supports persistent ("keep-alive") HTTP connections.

docs/transport.asciidoc

Lines changed: 68 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
[[transport]]
22
=== Transport
33

4-
The `elasticsearch-transport` library provides a low-level Ruby client for
5-
connecting to an {es} cluster.
4+
The `elastic-transport` library provides a low-level Ruby client for connecting to an {es} cluster. It currently powers the https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html[Elasticsearch Ruby] and the https://www.elastic.co/guide/en/enterprise-search-clients/ruby/current/index.html[Enterprise Search Ruby] clients.
65

7-
It handles connecting to multiple nodes in the cluster, rotating across
8-
connections, logging and tracing requests and responses, maintaining failed
9-
connections, discovering nodes in the cluster, and provides an abstraction for
10-
data serialization and transport.
6+
When available, it handles connecting to multiple nodes in the cluster, rotating across connections, logging and tracing requests and responses, maintaining failed connections, discovering nodes in the cluster, and provides an abstraction for data serialization and transport.
117

12-
It does not handle calling the {es} API.
13-
14-
The library is compatible with Ruby 1.9 or higher and with all versions of {es}
15-
since 0.90.
16-
17-
For optimal performance, use a HTTP library which supports persistent
18-
("keep-alive") connections, such as https://github.com/toland/patron[patron] or
19-
https://github.com/typhoeus/typhoeus[Typhoeus]. Require the library
20-
(require 'patron') in your code, and it will be automatically used.
8+
It does not handle calling the {es} or Enterprise Search APIs.
219

10+
For optimal performance, use a HTTP library which supports persistent ("keep-alive") connections, such as https://github.com/toland/patron[patron] or https://github.com/typhoeus/typhoeus[Typhoeus]. Require the library (require 'patron') in your code, and it will be automatically used.
2211

2312
[discrete]
2413
[[transport-install]]
@@ -27,21 +16,21 @@ https://github.com/typhoeus/typhoeus[Typhoeus]. Require the library
2716
Install the package from https://rubygems.org/[Rubygems]:
2817

2918
```
30-
gem install elasticsearch-transport
19+
gem install elastic-transport
3120
```
3221

3322
To use an unreleased version, either add it to your `Gemfile` for
3423
http://gembundler.com/[Bundler]:
3524

3625
```
37-
gem 'elasticsearch-transport', git: 'git://github.com/elasticsearch/elasticsearch-ruby.git'
26+
gem 'elastic-transport', git: 'git@github.com:elastic/elastic-transport-ruby.git'
3827
```
3928

4029
or install it from a source code checkout:
4130

4231
```
43-
git clone https://github.com/elasticsearch/elasticsearch-ruby.git
44-
cd elasticsearch-ruby/elasticsearch-transport
32+
git clone https://github.com/elastic/elastic-transport-ruby.git
33+
cd elastic-transport
4534
bundle install
4635
rake install
4736
```
@@ -51,32 +40,28 @@ rake install
5140
[[transport-example-usage]]
5241
==== Example usage
5342

54-
In the simplest form, connect to {es} running on http://localhost:9200 without
55-
any configuration:
43+
In the simplest form, connect to {es} running on http://localhost:9200 without any configuration:
5644

57-
```ruby
58-
require 'elasticsearch/transport'
45+
[source,rb]
46+
----------------------------
47+
require 'elastic/transport'
5948
60-
client = Elasticsearch::Client.new
61-
response = client.perform_request 'GET', '_cluster/health'
62-
# => #<Elasticsearch::Transport::Transport::Response:0x007fc5d506ce38 @status=200, @body={ ... } >
63-
```
49+
client = Elastic::Transport::Client.new
50+
response = client.perform_request('GET', '_cluster/health')
51+
# => #<Elastic::Transport::Transport::Response:0x007fc5d506ce38 @status=200, @body={ ... } >
52+
----------------------------
6453

65-
Full documentation is available at
66-
http://rubydoc.info/gems/elasticsearch-transport.
54+
Full documentation is available at http://rubydoc.info/gems/elastic-transport.
6755

6856
[discrete]
6957
[[transport-implementations]]
7058
==== Transport implementations
7159

72-
By default, the client uses the https://rubygems.org/gems/faraday[Faraday] HTTP
73-
library as a transport implementation.
60+
By default, the client uses the https://rubygems.org/gems/faraday[Faraday] HTTP library as a transport implementation.
7461

75-
It auto-detects and uses an adapter for Faraday based on gems loaded in your
76-
code, preferring HTTP clients with support for persistent connections.
62+
It auto-detects and uses an adapter for Faraday based on gems loaded in your code, preferring HTTP clients with support for persistent connections.
7763

78-
To use the https://github.com/toland/patron[Patron] HTTP, for example, require
79-
it:
64+
To use the https://github.com/toland/patron[Patron] HTTP, for example, require it:
8065

8166
```
8267
require 'patron'
@@ -85,7 +70,7 @@ require 'patron'
8570
Then, create a new client, and the Patron gem will be used as the "driver":
8671

8772
```ruby
88-
client = Elasticsearch::Client.new
73+
client = Elastic::Transport::Client.new
8974

9075
client.transport.connections.first.connection.builder.adapter
9176
# => Faraday::Adapter::Patron
@@ -105,41 +90,41 @@ end
10590
To use a specific adapter for Faraday, pass it as the `adapter` argument:
10691

10792
```ruby
108-
client = Elasticsearch::Client.new adapter: :net_http_persistent
93+
client = Elastic::Client.new(adapter: :net_http_persistent)
10994

11095
client.transport.connections.first.connection.builder.handlers
11196
# => [Faraday::Adapter::NetHttpPersistent]
11297
```
11398

114-
To pass options to the
115-
https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb[`Faraday::Connection`]
116-
constructor, use the `transport_options` key:
99+
When using the Elasticsearch or Enterprise Search clients, you can pass the `adapter` parameter when initializing the clients.
100+
101+
To pass options to the https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb[`Faraday::Connection`] constructor, use the `transport_options` key:
117102

118103
```ruby
119-
client = Elasticsearch::Client.new transport_options: {
120-
request: { open_timeout: 1 },
121-
headers: { user_agent: 'MyApp' },
122-
params: { :format => 'yaml' },
123-
ssl: { verify: false }
124-
}
104+
client = Elastic::Client.new(
105+
transport_options: {
106+
request: { open_timeout: 1 },
107+
headers: { user_agent: 'MyApp' },
108+
params: { :format => 'yaml' },
109+
ssl: { verify: false }
110+
}
111+
)
125112
```
126113

127114
To configure the Faraday instance directly, use a block:
128115

129116
```ruby
130117
require 'patron'
131118

132-
client = Elasticsearch::Client.new(host: 'localhost', port: '9200') do |f|
119+
client = Elastic::Client.new(host: 'localhost', port: '9200') do |f|
133120
f.response :logger
134121
f.adapter :patron
135122
end
136123
```
137124

138-
You can use any standard Faraday middleware and plugins in the configuration
139-
block.
125+
You can use any standard Faraday middleware and plugins in the configuration block.
140126

141-
You can also initialize the transport class yourself, and pass it to the client
142-
constructor as the `transport` argument:
127+
You can also initialize the transport class yourself, and pass it to the client constructor as the `transport` argument. The Elasticsearch and Enterprise Search clients accept `:transport` as parameter when initializing a client. So you can pass in a transport you've initialized with the following options:
143128

144129
```ruby
145130
require 'patron'
@@ -149,17 +134,17 @@ transport_configuration = lambda do |f|
149134
f.adapter :patron
150135
end
151136

152-
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
137+
transport = Elastic::Transport::Transport::HTTP::Faraday.new(
153138
hosts: [ { host: 'localhost', port: '9200' } ],
154139
&transport_configuration
140+
)
155141

156142
# Pass the transport to the client
157143
#
158-
client = Elasticsearch::Client.new transport: transport
144+
client = Elastic::Client.new(transport: transport)
159145
```
160146

161-
Instead of passing the transport to the constructor, you can inject it at run
162-
time:
147+
Instead of passing the transport to the constructor, you can inject it at run time:
163148

164149
```ruby
165150
# Set up the transport
@@ -169,85 +154,69 @@ faraday_configuration = lambda do |f|
169154
f.adapter :excon
170155
end
171156

172-
faraday_client = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
173-
hosts: [ { host: 'my-protected-host',
174-
port: '443',
175-
user: 'USERNAME',
176-
password: 'PASSWORD',
177-
scheme: 'https'
178-
}],
157+
faraday_client = Elastic::Transport::Transport::HTTP::Faraday.new(
158+
hosts: [
159+
{
160+
host: 'my-protected-host',
161+
port: '443',
162+
user: 'USERNAME',
163+
password: 'PASSWORD',
164+
scheme: 'https'
165+
}
166+
],
179167
&faraday_configuration
168+
)
180169

181170
# Create a default client
182171
#
183-
client = Elasticsearch::Client.new
172+
client = Elastic::Client.new
184173

185174
# Inject the transport to the client
186175
#
187176
client.transport = faraday_client
188177
```
189178

190-
You can also use a bundled https://rubygems.org/gems/curb[Curb] based transport
191-
implementation:
179+
You can also use a bundled https://rubygems.org/gems/curb[Curb] based transport implementation:
192180

193181
```ruby
194182
require 'curb'
195-
require 'elasticsearch/transport/transport/http/curb'
183+
require 'elastic/transport/transport/http/curb'
196184

197-
client = Elasticsearch::Client.new transport_class: Elasticsearch::Transport::Transport::HTTP::Curb
185+
client = Elastic::Client.new(transport_class: Elastic::Transport::Transport::HTTP::Curb)
198186

199187
client.transport.connections.first.connection
200188
# => #<Curl::Easy http://localhost:9200/>
201189
```
202190

203-
It's possible to customize the Curb instance by passing a block to the
204-
constructor as well (in this case, as an inline block):
191+
It's possible to customize the Curb instance by passing a block to the constructor as well (in this case, as an inline block):
205192

206193
```ruby
207-
transport = Elasticsearch::Transport::Transport::HTTP::Curb.new \
194+
transport = Elastic::Transport::Transport::HTTP::Curb.new(
208195
hosts: [ { host: 'localhost', port: '9200' } ],
209196
& lambda { |c| c.verbose = true }
197+
)
210198

211-
client = Elasticsearch::Client.new transport: transport
199+
client = Elastic::Client.new(transport: transport)
212200
```
213201

214-
You can write your own transport implementation by including the
215-
{Elasticsearch::Transport::Transport::Base} module, implementing the required
216-
contract, and passing it to the client as the `transport_class` parameter – or
217-
by injecting it directly.
202+
You can write your own transport implementation by including the {Elastic::Transport::Transport::Base} module, implementing the required contract, and passing it to the client as the `transport_class` parameter – or by injecting it directly.
218203

219204
[discrete]
220205
[[transport-architecture]]
221206
==== Transport architecture
222207

223-
* `Elasticsearch::Transport::Client` is composed of
224-
`Elasticsearch::Transport::Transport`.
208+
* `Elastic::Transport::Client` is composed of `Elastic::Transport::Transport`.
225209

226-
* `Elasticsearch::Transport::Transport` is composed of
227-
`Elasticsearch::Transport::Transport::Connections`, and an instance of logger,
228-
tracer, serializer and sniffer.
210+
* `Elastic::Transport::Transport` is composed of `Elastic::Transport::Transport::Connections`, and an instance of logger, tracer, serializer and sniffer.
229211

230-
* Logger and tracer can be any object conforming to Ruby logging interface, for
231-
example, an instance of
232-
https://ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html[`Logger`],
233-
https://rubygems.org/gems/log4r[log4r],
234-
https://github.com/TwP/logging/[logging], and so on.
212+
* Logger and tracer can be any object conforming to Ruby logging interface, for example, an instance of https://ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html[`Logger`], https://rubygems.org/gems/log4r[log4r], https://github.com/TwP/logging/[logging], and so on.
235213

236-
* The `Elasticsearch::Transport::Transport::Serializer::Base` implementations
237-
handle converting data for {es} (for example, to JSON). You can implement your
238-
own serializer.
214+
* The `Elastic::Transport::Transport::Serializer::Base` implementations handle converting data for {es} (for example, to JSON). You can implement your own serializer.
239215

240-
* `Elasticsearch::Transport::Transport::Sniffer` allows to discover nodes in the
241-
cluster and use them as connections.
216+
* `Elastic::Transport::Transport::Sniffer` allows to discover nodes in the cluster and use them as connections.
242217

243-
* `Elasticsearch::Transport::Transport::Connections::Collection` is composed of
244-
`Elasticsearch::Transport::Transport::Connections::Connection` instances and a
245-
selector instance.
218+
* `Elastic::Transport::Transport::Connections::Collection` is composed of `Elastic::Transport::Transport::Connections::Connection` instances and a selector instance.
246219

247-
* `Elasticsearch::Transport::Transport::Connections::Connection` contains the
248-
connection attributes such as hostname and port, as well as the concrete
249-
persistent "session" connected to a specific node.
220+
* `Elastic::Transport::Transport::Connections::Connection` contains the connection attributes such as hostname and port, as well as the concrete persistent "session" connected to a specific node.
250221

251-
* The `Elasticsearch::Transport::Transport::Connections::Selector::Base`
252-
implementations allow to choose connections from the pool, for example, in a
253-
round-robin or random fashion. You can implement your own selector strategy.
222+
* The `Elastic::Transport::Transport::Connections::Selector::Base` implementations allow to choose connections from the pool, for example, in a round-robin or random fashion. You can implement your own selector strategy.

0 commit comments

Comments
 (0)