elastomer-client 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +15 -0
- data/README.md +6 -7
- data/Rakefile +21 -0
- data/docs/README.md +44 -0
- data/docs/bulk_indexing.md +3 -0
- data/docs/client.md +240 -0
- data/docs/cluster.md +148 -0
- data/docs/docs.md +254 -0
- data/docs/index.md +161 -0
- data/docs/multi_search.md +3 -0
- data/docs/notifications.md +24 -11
- data/docs/scan_scroll.md +3 -0
- data/docs/snapshots.md +3 -0
- data/docs/templates.md +3 -0
- data/docs/warmers.md +3 -0
- data/elastomer-client.gemspec +2 -2
- data/lib/elastomer/client.rb +70 -43
- data/lib/elastomer/client/bulk.rb +2 -2
- data/lib/elastomer/client/cluster.rb +2 -2
- data/lib/elastomer/client/docs.rb +190 -54
- data/lib/elastomer/client/errors.rb +4 -2
- data/lib/elastomer/client/index.rb +111 -43
- data/lib/elastomer/client/multi_search.rb +1 -1
- data/lib/elastomer/client/nodes.rb +9 -4
- data/lib/elastomer/client/repository.rb +2 -2
- data/lib/elastomer/client/scroller.rb +235 -0
- data/lib/elastomer/client/snapshot.rb +1 -1
- data/lib/elastomer/client/template.rb +1 -1
- data/lib/elastomer/client/warmer.rb +1 -1
- data/lib/elastomer/notifications.rb +1 -1
- data/lib/elastomer/version.rb +1 -1
- data/script/bootstrap +0 -7
- data/script/cibuild +8 -3
- data/script/test +6 -0
- data/test/client/bulk_test.rb +2 -2
- data/test/client/cluster_test.rb +23 -2
- data/test/client/docs_test.rb +137 -6
- data/test/client/errors_test.rb +12 -8
- data/test/client/index_test.rb +88 -5
- data/test/client/multi_search_test.rb +29 -0
- data/test/client/repository_test.rb +36 -37
- data/test/client/{scan_test.rb → scroller_test.rb} +25 -6
- data/test/client/snapshot_test.rb +53 -43
- data/test/client/stubbed_client_test.rb +1 -1
- data/test/client_test.rb +60 -0
- data/test/notifications_test.rb +69 -0
- data/test/test_helper.rb +54 -11
- metadata +36 -23
- data/.ruby-version +0 -1
- data/lib/elastomer/client/scan.rb +0 -161
- data/script/testsuite +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ef2b4c790e85cb9d9141c34ae1945b230cadeb8
|
4
|
+
data.tar.gz: 463229368a9644620aab366e4ad67efa393e47fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 904e906d03a23949bc0725932be4d7aaf6cd23185ab5a382160c7611e6c500adc03283813068a3fdfca5d067253736b309c7a74767d0c1a1a0d28b6a5e689689
|
7
|
+
data.tar.gz: 0f0d9fcb4527e8a0b1e43df7fba7c2d5fb822c78e8270e4ec4e239d0439647bbe6afbe2f569093ec0cffed21623187b1420ee3d7c4b4ae5148f6dd8accbe7ef9
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 0.5.0 (2015-01-21)
|
2
|
+
- BREAKING: rename action.available notification to action.ping
|
3
|
+
- Index Component
|
4
|
+
- client.index no longer requires a name
|
5
|
+
- Documents Component
|
6
|
+
- client.docs no longer requires an index name
|
7
|
+
- added an `exists?` method
|
8
|
+
- added `termvector` and `multi_termvectors` methods
|
9
|
+
- added a `search_shards` method
|
10
|
+
- added an `mget` alias for `multi_get`
|
11
|
+
- Adding more documentation
|
12
|
+
- Rename client.available? to client.ping (aliased as available?)
|
13
|
+
- Updating tests to pass with ES 1.4.X
|
14
|
+
- Enabling regular scroll queries vi `Client#scroll`
|
15
|
+
|
1
16
|
## 0.4.1 (2014-10-14)
|
2
17
|
- Support for index `_recovery` endpoint
|
3
18
|
- Fix Faraday 0.8 support
|
data/README.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
# Elastomer
|
1
|
+
# Elastomer Client [](https://travis-ci.org/github/elastomer-client)
|
2
2
|
|
3
3
|
Making a stupid simple ElasticSearch client so your project can be smarter!
|
4
4
|
|
5
5
|
## Getting Started
|
6
6
|
|
7
|
-
|
7
|
+
Get started by cloning and running a few scripts:
|
8
8
|
|
9
9
|
```
|
10
10
|
$ git clone https://github.com/github/elastomer-client.git
|
11
11
|
$ cd elastomer-client
|
12
12
|
$ script/bootstrap
|
13
|
-
$ script/
|
13
|
+
$ script/test
|
14
14
|
```
|
15
15
|
|
16
16
|
## Client
|
@@ -75,10 +75,9 @@ index.delete
|
|
75
75
|
|
76
76
|
#### Docs
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
type.
|
78
|
+
The [Docs](lib/elastomer/client/docs.rb) class handles the indexing and
|
79
|
+
searching of documents. Each instance is scoped to an index and optionally a
|
80
|
+
document type.
|
82
81
|
|
83
82
|
```ruby
|
84
83
|
require 'elastomer/client'
|
data/Rakefile
CHANGED
@@ -7,3 +7,24 @@ Rake::TestTask.new do |t|
|
|
7
7
|
end
|
8
8
|
|
9
9
|
task :default => :test
|
10
|
+
|
11
|
+
namespace :actions do
|
12
|
+
desc "list valid actions"
|
13
|
+
task :list do
|
14
|
+
# there are two distinct :action declarations we need to find
|
15
|
+
# the regular expressions below capture both
|
16
|
+
#
|
17
|
+
# [:action] = 'some.value'
|
18
|
+
# :action => 'some.value'
|
19
|
+
#
|
20
|
+
list = %x(grep '\\[\\?:action\\]\\?\\s\\+=' `find lib -name '*.rb'`).split("\n")
|
21
|
+
list.map! do |line|
|
22
|
+
m = /\A.*?\[?:action\]?\s+=>?\s+'(.*?)'.*\Z/.match line
|
23
|
+
m.nil? ? nil : m[1]
|
24
|
+
end
|
25
|
+
|
26
|
+
list.compact.sort.uniq.each do |action|
|
27
|
+
STDOUT.puts "- #{action}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/docs/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Elastomer Client in Depth
|
2
|
+
|
3
|
+
We first started building the Elastomer Client gem when an
|
4
|
+
[official client](https://github.com/elasticsearch/elasticsearch-ruby)
|
5
|
+
was not yet available from ElasticSearch. We were looking for a client that
|
6
|
+
provided a one-to-one mapping of the ElasticSearch APIs and avoided higher level
|
7
|
+
complexity such as connection pooling, round-robin connections, thrift support,
|
8
|
+
and the like. We think these things these things are bettered handled at
|
9
|
+
different layers and by other software libraries.
|
10
|
+
|
11
|
+
Our goal is to keep our ElasticSearch client simple and then compose
|
12
|
+
higher level functionality from smaller components. This is the UNIX philosophy
|
13
|
+
in action.
|
14
|
+
|
15
|
+
To that end we have tried to be as faithful as possible to the ElasticSearch API
|
16
|
+
with our implementation. There are a few places where it made sense to wrap the
|
17
|
+
ElasticSearch API inside Ruby idioms. One notable location is the
|
18
|
+
[scan-scroll](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/scan-scroll.html)
|
19
|
+
search type; the Elastomer Client provides a Ruby iterator to work with these
|
20
|
+
types of queries.
|
21
|
+
|
22
|
+
Below are links to documents describing the various components of the Elastomer
|
23
|
+
Client library. Start with the core components - specifically the **Client**
|
24
|
+
document. All the other components are built atop the client.
|
25
|
+
|
26
|
+
**Core Components**
|
27
|
+
|
28
|
+
* [Client](client.md)
|
29
|
+
* [Index](index.md)
|
30
|
+
* [Documents](docs.md)
|
31
|
+
* [Cluster](cluster.md)
|
32
|
+
* [Templates](templates.md)
|
33
|
+
* [Warmers](warmers.md)
|
34
|
+
|
35
|
+
**Bulk Components**
|
36
|
+
|
37
|
+
* [Bulk Indexing](bulk_indexing.md)
|
38
|
+
* [Multi-Search](multi_search.md)
|
39
|
+
* [Scan/Scroll](scan_scroll.md)
|
40
|
+
|
41
|
+
**Operational Components**
|
42
|
+
|
43
|
+
* [Snapshots](snapshots.md)
|
44
|
+
* [Notifications](notifications.md)
|
data/docs/client.md
ADDED
@@ -0,0 +1,240 @@
|
|
1
|
+
# Elastomer Client Component
|
2
|
+
|
3
|
+
All methods in the Elastomer Client gem eventually make an HTTP request to
|
4
|
+
ElasticSearch. The [`Elastomer::Client`](https://github.com/github/elastomer-client/blob/master/lib/elastomer/client.rb)
|
5
|
+
class is responsible for connecting to an ElasticSearch instance, making HTTP
|
6
|
+
requests, processing the response, and handling errors. Let's look at the
|
7
|
+
details of how `Elastomer::Client` handles HTTP communication.
|
8
|
+
|
9
|
+
### Connecting
|
10
|
+
|
11
|
+
We use the [Faraday](https://github.com/lostisland/faraday) gem for all HTTP
|
12
|
+
communication. Faraday provides a uniform wrapper around several different HTTP
|
13
|
+
clients allowing any of these clients to be used at runtime. Faraday also has
|
14
|
+
the concept of *middlewares* that operate on the HTTP request and response. We
|
15
|
+
use Faraday middleware to encode and decode JSON messages exchanged with
|
16
|
+
ElasticSearch.
|
17
|
+
|
18
|
+
Without any options the `Elastomer::Client` will connect to the default
|
19
|
+
ElasticSearch URL `http://localhost:9200`. The `Net:HTTP` client from the Ruby
|
20
|
+
standard library will be used.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
client = Elastomer::Client.new
|
24
|
+
client.host #=> 'localhost'
|
25
|
+
client.port #=> 9200
|
26
|
+
client.url #=> 'http://localhost:9200'
|
27
|
+
```
|
28
|
+
|
29
|
+
[Boxen](https://boxen.github.com) configures ElasticSearch to listen on port
|
30
|
+
`19200` instead of the standard port. We can provide either the full URL or just
|
31
|
+
a different port number if ElasticSearch is running on `localhost`.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
client = Elastomer::Client.new :port => 19200
|
35
|
+
client.host #=> 'localhost'
|
36
|
+
client.port #=> 19200
|
37
|
+
client.url #=> 'http://localhost:19200'
|
38
|
+
|
39
|
+
client = Elastomer::Client.new :url => "http://localhost:19200"
|
40
|
+
```
|
41
|
+
|
42
|
+
ElasticSearch works best with persistent connections. We can use the
|
43
|
+
`Net::HTTP::Persistent` adapter with Faraday.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
client = Elastomer::Client.new \
|
47
|
+
:port => 19200,
|
48
|
+
:adapter => :net_http_persistent
|
49
|
+
```
|
50
|
+
|
51
|
+
We also want to configure the `:open_timeout` (for making the initial connection
|
52
|
+
to ElasticSearch) and the `:read_timeout` (used to limit each request). The open
|
53
|
+
timeout should be short - it defaults to 2 seconds. The read timeout should be
|
54
|
+
longer, but it can vary depending upon the type of request you are making. Large
|
55
|
+
bulk requests will take longer than a quick count query.
|
56
|
+
|
57
|
+
The open timeout is configured once when the client is first created. The read
|
58
|
+
timeout can be set for each request.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
client = Elastomer::Client.new \
|
62
|
+
:url => "http:/localhost:19200",
|
63
|
+
:adapter => :net_http_persistent,
|
64
|
+
:open_timeout => 1,
|
65
|
+
:read_timeout => 5
|
66
|
+
|
67
|
+
client.get("/", :read_timeout => 1)
|
68
|
+
```
|
69
|
+
|
70
|
+
Because each library handles read timeouts differently, some caution must be
|
71
|
+
used. Persistent connections might or might not be closed and reopened when the
|
72
|
+
read timeout is reached. If the connection is left open and reused, then the
|
73
|
+
returned data might actually be from a previous request. This can lead to all
|
74
|
+
kinds of horrible data leaks.
|
75
|
+
|
76
|
+
ElasticSearch provides an `X-Opaque-Id` request header. Any value set in this
|
77
|
+
request header will be returned in the corresponding response header. This
|
78
|
+
allows the client to correlate the response from ElasticSearch with the request
|
79
|
+
that was submitted. We have written an
|
80
|
+
[OpaqueId](https://github.com/github/elastomer-client/blob/master/lib/elastomer/middleware/opaque_id.rb)
|
81
|
+
middleware that will abort any request if the `X-Opaque-Id` headers disagree
|
82
|
+
between the request and the response. You can use this feature by setting
|
83
|
+
the `:opaque_id` flag.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
client = Elastomer::Client.new \
|
87
|
+
:url => "http://localhost:19200",
|
88
|
+
:adapter => :net_http_persistent,
|
89
|
+
:opaque_id => true
|
90
|
+
```
|
91
|
+
|
92
|
+
If you are not using persistent connections, then you do not need to worry about
|
93
|
+
`X-Opaque-Id` headers.
|
94
|
+
|
95
|
+
### HTTP Methods
|
96
|
+
|
97
|
+
The standard HTTP verbs - `head`, `get`, `put`, `post`, `delete` - are exposed
|
98
|
+
as methods on the `Elastomer::Client` class. Each method accepts a path and a
|
99
|
+
Hash of parameters. Some parameters are applied as path expansions, some are
|
100
|
+
reserved, and the remainder are used as URL parameters. We'll look at the
|
101
|
+
reserved parameters first.
|
102
|
+
|
103
|
+
#### Reserved Parameters
|
104
|
+
|
105
|
+
**:body**
|
106
|
+
|
107
|
+
The value passed in as the `:body` parameter will be used as the body of the
|
108
|
+
HTTP request. The HTTP `head` method does not support a request body and ignores
|
109
|
+
this parameter. The other HTTP methods all support request bodies.
|
110
|
+
|
111
|
+
The `:body` value will be converted into JSON format before being sent to
|
112
|
+
ElasticSearch unless the body is a String or an Array. If the body is a String
|
113
|
+
it is assumed to already be JSON formatted, and it is sent to ElasticSearch as
|
114
|
+
is without any modifications. When the body is an Array then all the items are
|
115
|
+
joined with a newline character `\n` and a trailing newline is appended; this
|
116
|
+
supports [bulk](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html)
|
117
|
+
indexing and [multi-search](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html)
|
118
|
+
requests.
|
119
|
+
|
120
|
+
**:read_timeout**
|
121
|
+
|
122
|
+
The read timeout for the HTTP network calls can be changed on a per-call basis.
|
123
|
+
If a `:read_timeout` is supplied then it will be used instead of the global read
|
124
|
+
timeout configured during initialization. This is useful for large bulk
|
125
|
+
operations that might take longer than normal.
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
client.cluster.health \
|
129
|
+
:index => "test-index-1",
|
130
|
+
:wait_for_status => "green",
|
131
|
+
:timeout => "5s",
|
132
|
+
:read_timeout => 7
|
133
|
+
```
|
134
|
+
|
135
|
+
In the example above we are waiting for the named index to reach a green state.
|
136
|
+
The `:timeout` of 5 seconds is passed to ElasticSearch. This call will return
|
137
|
+
after 5 seconds even if the index has not yet reached green status. So we set
|
138
|
+
our network call timeout to 7 seconds to ensure we don't kill the request before
|
139
|
+
ElasticSearch has responded.
|
140
|
+
|
141
|
+
**:action** and **:context**
|
142
|
+
|
143
|
+
Each method in the Elastomer client gem has its own `:action` value that is
|
144
|
+
used in conjunction with the [notifications](notifications.md) layer. The
|
145
|
+
`:action` parameter cannot be changed by the user. Instead you can provide a
|
146
|
+
`:context` value to each method call. This will be passed unchanged to the
|
147
|
+
notifications layer, and it is useful for tracking where an Elastomer client
|
148
|
+
method is called from within your application.
|
149
|
+
|
150
|
+
#### URL Handling
|
151
|
+
|
152
|
+
URLs are generated by combining a URL template with values extracted from the
|
153
|
+
parameters. The [Addressable](https://github.com/sporkmonger/addressable) gem is
|
154
|
+
used for this URL template expansion.
|
155
|
+
|
156
|
+
With the [`Addressable::Template`](https://github.com/sporkmonger/addressable#uri-templates)
|
157
|
+
a typical search URL takes the form `{/index}{/type}/_search`. The `:index` and
|
158
|
+
`:type` values are taken from the parameters Hash and combined with the template
|
159
|
+
to generate the URL. The internal
|
160
|
+
[`expand_path`](https://github.com/github/elastomer-client/blob/master/lib/elastomer/client.rb#L245)
|
161
|
+
method handles the URL generation.
|
162
|
+
|
163
|
+
Here are a few examples to better illustrate the concept.
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
client.expand_path("{/index}{/type}/_search", {
|
167
|
+
:q => "*:*"
|
168
|
+
})
|
169
|
+
#=> "/_search?q=*:*"
|
170
|
+
|
171
|
+
client.expand_path("{/index}{/type}/_search", {
|
172
|
+
:index => "twitter",
|
173
|
+
:q => "*:*"
|
174
|
+
})
|
175
|
+
#=> "/twitter/_search?q=*:*"
|
176
|
+
|
177
|
+
client.expand_path("{/index}{/type}/_search", {
|
178
|
+
:index => "twitter",
|
179
|
+
:type => "tweet",
|
180
|
+
:q => "*:*"
|
181
|
+
})
|
182
|
+
#=> "/twitter/tweet/_search?q=*:*"
|
183
|
+
|
184
|
+
client.expand_path("{/index}{/type}/_search", {
|
185
|
+
:index => "twitter",
|
186
|
+
:type => ["tweet", "user"],
|
187
|
+
:q => "*:*"
|
188
|
+
:search_type => "count"
|
189
|
+
})
|
190
|
+
#=> "/twitter/tweet,user/_search?q=*:*&search_type=count"
|
191
|
+
```
|
192
|
+
|
193
|
+
In the examples above the path elements are optional. We can force them to be
|
194
|
+
required and non-empty using a slightly different template syntax. In the
|
195
|
+
example below we are requiring the `:index` and `:type` parameters to be
|
196
|
+
provided. If either of them are missing (or nil or an empty string) then an
|
197
|
+
`ArgumentError` is raised.
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
client.expand_path("/{index}/{type}/_search", {
|
201
|
+
:index => "twitter",
|
202
|
+
:q => "*:*"
|
203
|
+
})
|
204
|
+
#=> raises an ArgumentError - :type is missing
|
205
|
+
|
206
|
+
client.expand_path("/{index}/{type}/_search", {
|
207
|
+
:index => "twitter",
|
208
|
+
:type => " ",
|
209
|
+
:q => "*:*"
|
210
|
+
})
|
211
|
+
#=> raises an ArgumentError - :type is an empty string
|
212
|
+
```
|
213
|
+
|
214
|
+
And that is the basic concept of the `expand_path` method. The URL template
|
215
|
+
pattern is used extensively in the Elastomer client code, so it is definitely
|
216
|
+
worth knowing about.
|
217
|
+
|
218
|
+
### Errors
|
219
|
+
|
220
|
+
Invariably things will go wrong where computers and networks are involved. The
|
221
|
+
Elastomer client code makes no attempt to retry an operation in the face of an
|
222
|
+
error. However, it does classify errors into *fatal* and *retryable* exceptions.
|
223
|
+
|
224
|
+
Each class that inherits from
|
225
|
+
[`Elastomer::Client::Error`](https://github.com/github/elastomer-client/blob/master/lib/elastomer/client/errors.rb)
|
226
|
+
has a `fatal?` method (and the inverse `retry?` method). If an exception is
|
227
|
+
fatal, then the request is fundamentally flawed and should not be retried.
|
228
|
+
Passing a malformed search query or trying to search an index that does not
|
229
|
+
exist are both examples of fatal errors - the request will never succeed.
|
230
|
+
|
231
|
+
If an error is not fatal then it can be retried. If the ElasticSearch cluster
|
232
|
+
has a full search queue then any query will fail. It not the fault of the user
|
233
|
+
or the query itself - ElasticSearch just needs more capacity. The query can be
|
234
|
+
safely retried.
|
235
|
+
|
236
|
+
Therein lies the rub, though. Retrying a search or any operation will continue
|
237
|
+
to add load to a search cluster that might already be experiencing problems.
|
238
|
+
Blindly retrying an operation might do more harm than good. It is left to the
|
239
|
+
user to implement their own exponential back-off scheme or to implement some
|
240
|
+
status / back-pressure system.
|
data/docs/cluster.md
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
# Elastomer Cluster Component
|
2
|
+
|
3
|
+
The cluster component deals with commands for managing cluster state and
|
4
|
+
monitoring cluster health. All the commands found under the
|
5
|
+
[cluster API](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster.html)
|
6
|
+
section of the ElasticSearch documentation are implemented by the
|
7
|
+
[`cluster.rb`](https://github.com/github/elastomer-client/blob/master/lib/elastomer/client/cluster.rb)
|
8
|
+
module and the [`nodes.rb`](https://github.com/github/elastomer-client/blob/master/lib/elastomer/client/nodes.rb)
|
9
|
+
module.
|
10
|
+
|
11
|
+
## Cluster
|
12
|
+
|
13
|
+
API endpoints dealing with cluster level information and settings are found in
|
14
|
+
the [`Cluster`](lib/elastomer/client/cluster.rb) class. Each of these methods
|
15
|
+
corresponds to an API endpoint described in the ElasticSearch documentation
|
16
|
+
(linked to above). The params listed in the documentation can be passed to these
|
17
|
+
methods, so we do not take too much trouble to enumerate them all.
|
18
|
+
|
19
|
+
#### health
|
20
|
+
|
21
|
+
The cluster [health API](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-health.html)
|
22
|
+
returns a very simple cluster health status report.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'elastomer/client'
|
26
|
+
client = Elastomer::Client.new :port => 19200
|
27
|
+
|
28
|
+
# the current health summary
|
29
|
+
client.cluster.health
|
30
|
+
```
|
31
|
+
|
32
|
+
You can wait for a *yellow* status.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
client.cluster.health \
|
36
|
+
:wait_for_status => "yellow",
|
37
|
+
:timeout => "10s",
|
38
|
+
:read_timeout => 12
|
39
|
+
```
|
40
|
+
|
41
|
+
And you can request index level health details. The default timeout for the
|
42
|
+
health endpoint is 30 seconds; hence, we set our read timeout to 32 seconds.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
client.cluster.health \
|
46
|
+
:level => "indices",
|
47
|
+
:read_timeout => 32
|
48
|
+
```
|
49
|
+
|
50
|
+
#### state & stats
|
51
|
+
|
52
|
+
If you need something more than basic health information, then the
|
53
|
+
[`state`](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-state.html)
|
54
|
+
and [`stats`](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-stats.html)
|
55
|
+
endpoints are the next methods to call. Please look through the API
|
56
|
+
documentation linked to above for all the details. And you can play with these
|
57
|
+
endpoints via an IRB session.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
# detailed cluster state information
|
61
|
+
client.cluster.state
|
62
|
+
|
63
|
+
# cluster wide statistics
|
64
|
+
client.cluster.stats
|
65
|
+
```
|
66
|
+
|
67
|
+
#### settings
|
68
|
+
|
69
|
+
Cluster behavior is controlled via the
|
70
|
+
[settings API](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-update-settings.html).
|
71
|
+
The settings can be retrieved, and some settings can be modified at runtime to
|
72
|
+
control shard allocations, routing, index replicas, and so forth. For example,
|
73
|
+
when performing a [rolling restart](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_rolling_restarts.html)
|
74
|
+
of a cluster, disabling shard allocation between restarts can reduce the
|
75
|
+
cluster recovery time.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
# disable all shard allocation
|
79
|
+
client.cluster.update_settings :transient => {
|
80
|
+
"cluster.routing.allocation.enable" => "none"
|
81
|
+
}
|
82
|
+
|
83
|
+
# shutdown the local node
|
84
|
+
client.nodes('_local').shutdown
|
85
|
+
|
86
|
+
# restart the local node and wait for it to rejoin the cluster
|
87
|
+
|
88
|
+
# re-enable shard allocation
|
89
|
+
client.cluster.update_settings :transient => {
|
90
|
+
"cluster.routing.allocation.enable" => "all"
|
91
|
+
}
|
92
|
+
```
|
93
|
+
|
94
|
+
#### extras
|
95
|
+
|
96
|
+
We've added a few extras to the `cluster` module purely for convenience. These
|
97
|
+
are not API mappings; they are requests we frequently make from our
|
98
|
+
applications.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
# the list of all index templates
|
102
|
+
client.cluster.templates
|
103
|
+
|
104
|
+
# list all the indices in the cluster
|
105
|
+
client.cluster.indices
|
106
|
+
|
107
|
+
# list all nodes that are currently part of the cluster
|
108
|
+
client.cluster.nodes
|
109
|
+
```
|
110
|
+
|
111
|
+
Using these methods we can quickly get the names of all the indices in the
|
112
|
+
cluster. The `indices` method returns a hash of the index settings keyed by the
|
113
|
+
index name.
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
client.cluster.indices.keys
|
117
|
+
```
|
118
|
+
|
119
|
+
The same method can be used for getting all the template names, as well.
|
120
|
+
|
121
|
+
## Nodes
|
122
|
+
|
123
|
+
There are also node level API methods that provide stats and information for
|
124
|
+
individual (or multiple) nodes in the cluster. We expose these via the `nodes`
|
125
|
+
module in elastomer-client.
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
require 'elastomer/client'
|
129
|
+
client = Elastomer::Client.new :port => 19200
|
130
|
+
|
131
|
+
# gather OS, JVM, and process information from the local node
|
132
|
+
client.nodes("_local").info(:info => %w[os jvm process])
|
133
|
+
```
|
134
|
+
|
135
|
+
More than one node can be queried at the same time.
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
client.nodes(%w[node-1.local node-2.local]).stats(:stats => %w[os process])
|
139
|
+
```
|
140
|
+
|
141
|
+
Or you can query all nodes.
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
client.nodes("_all").stats(:stats => "fs")
|
145
|
+
```
|
146
|
+
|
147
|
+
Take a look at the source code documentation for all the API calls provided by
|
148
|
+
elastomer-client.
|