elastomer-client 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +18 -9
- data/CHANGELOG.md +5 -1
- data/README.md +2 -2
- data/docs/notifications.md +0 -4
- data/elastomer-client.gemspec +6 -4
- data/lib/elastomer/client/cluster.rb +28 -61
- data/lib/elastomer/client/docs.rb +0 -27
- data/lib/elastomer/client/index.rb +3 -52
- data/lib/elastomer/client/repository.rb +3 -3
- data/lib/elastomer/client/scroller.rb +1 -2
- data/lib/elastomer/client/snapshot.rb +3 -3
- data/lib/elastomer/middleware/encode_json.rb +8 -1
- data/lib/elastomer/version.rb +1 -1
- data/script/cibuild +6 -2
- data/test/client/bulk_test.rb +28 -6
- data/test/client/cluster_test.rb +28 -32
- data/test/client/docs_test.rb +5 -49
- data/test/client/index_test.rb +15 -83
- data/test/client/nodes_test.rb +18 -20
- data/test/client/percolator_test.rb +1 -1
- data/test/client/repository_test.rb +79 -83
- data/test/client/snapshot_test.rb +91 -91
- data/test/client/template_test.rb +1 -10
- data/test/client_test.rb +1 -7
- data/test/middleware/encode_json_test.rb +12 -4
- data/test/notifications_test.rb +4 -4
- data/test/test_helper.rb +10 -43
- metadata +33 -6
- data/script/test +0 -6
@@ -28,11 +28,11 @@ module Elastomer
|
|
28
28
|
def exists?(params = {})
|
29
29
|
response = client.get "/_snapshot{/repository}", update_params(params, :action => "repository.exists")
|
30
30
|
response.success?
|
31
|
-
rescue Elastomer::Client::Error =>
|
32
|
-
if
|
31
|
+
rescue Elastomer::Client::Error => err
|
32
|
+
if err.error && err.error.dig("root_cause", 0, "type") == "repository_missing_exception"
|
33
33
|
false
|
34
34
|
else
|
35
|
-
raise
|
35
|
+
raise err
|
36
36
|
end
|
37
37
|
end
|
38
38
|
alias_method :exist?, :exists?
|
@@ -102,8 +102,7 @@ module Elastomer
|
|
102
102
|
response = get "/_search/scroll", :body => scroll_id, :scroll => scroll, :action => "search.scroll"
|
103
103
|
response.body
|
104
104
|
rescue RequestError => err
|
105
|
-
if err.error && err.error["caused_by"]["type"] == "search_context_missing_exception"
|
106
|
-
|| err.message =~ /SearchContextMissingException/
|
105
|
+
if err.error && err.error["caused_by"]["type"] == "search_context_missing_exception"
|
107
106
|
raise SearchContextMissing, "No search context found for scroll ID #{scroll_id.inspect}"
|
108
107
|
else
|
109
108
|
raise err
|
@@ -37,11 +37,11 @@ module Elastomer
|
|
37
37
|
def exists?(params = {})
|
38
38
|
response = client.get "/_snapshot/{repository}/{snapshot}", update_params(params, :action => "snapshot.exists")
|
39
39
|
response.success?
|
40
|
-
rescue Elastomer::Client::Error =>
|
41
|
-
if
|
40
|
+
rescue Elastomer::Client::Error => err
|
41
|
+
if err.error && err.error.dig("root_cause", 0, "type") == "snapshot_missing_exception"
|
42
42
|
false
|
43
43
|
else
|
44
|
-
raise
|
44
|
+
raise err
|
45
45
|
end
|
46
46
|
end
|
47
47
|
alias_method :exist?, :exists?
|
@@ -23,8 +23,8 @@ module Elastomer
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def match_content_type(env)
|
26
|
+
add_content_type!(env)
|
26
27
|
if process_request?(env)
|
27
|
-
env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE
|
28
28
|
yield env[:body] unless env[:body].respond_to?(:to_str)
|
29
29
|
end
|
30
30
|
end
|
@@ -43,6 +43,13 @@ module Elastomer
|
|
43
43
|
type = type.split(";", 2).first if type.index(";")
|
44
44
|
type
|
45
45
|
end
|
46
|
+
|
47
|
+
def add_content_type!(env)
|
48
|
+
method = env[:method]
|
49
|
+
if method == :put || method == :post || has_body?(env)
|
50
|
+
env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE
|
51
|
+
end
|
52
|
+
end
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
data/lib/elastomer/version.rb
CHANGED
data/script/cibuild
CHANGED
@@ -14,10 +14,14 @@ echo
|
|
14
14
|
|
15
15
|
result=0
|
16
16
|
|
17
|
-
export RBENV_VERSION="2.
|
17
|
+
export RBENV_VERSION="2.3.3"
|
18
|
+
if [ -d /usr/share/rbenv/shims ]; then
|
19
|
+
export PATH=/usr/share/rbenv/shims:$PATH
|
20
|
+
fi
|
18
21
|
ruby -v
|
22
|
+
rm -f Gemfile.lock
|
19
23
|
script/bootstrap
|
20
|
-
|
24
|
+
bundle exec rake test || result=$?
|
21
25
|
|
22
26
|
if [ $result -ne 0 ]; then
|
23
27
|
exit $result
|
data/test/client/bulk_test.rb
CHANGED
@@ -87,10 +87,20 @@ describe Elastomer::Client::Bulk do
|
|
87
87
|
|
88
88
|
assert_kind_of Integer, h["took"]
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
assert_equal 2, h["items"].length
|
91
|
+
|
92
|
+
if es_version_2_x?
|
93
|
+
assert_bulk_index h["items"].first
|
94
|
+
assert_bulk_create h["items"].last
|
95
|
+
book_id = items.last["create"]["_id"]
|
96
|
+
elsif es_version_5_x?
|
97
|
+
assert_bulk_index h["items"].first
|
98
|
+
assert_bulk_index h["items"].last
|
99
|
+
book_id = items.last["index"]["_id"]
|
100
|
+
else
|
101
|
+
fail "Unknown ES version!"
|
102
|
+
end
|
92
103
|
|
93
|
-
book_id = items.last["create"]["_id"]
|
94
104
|
assert_match %r/^\S{20,22}$/, book_id
|
95
105
|
|
96
106
|
@index.refresh
|
@@ -108,10 +118,22 @@ describe Elastomer::Client::Bulk do
|
|
108
118
|
end
|
109
119
|
items = h["items"]
|
110
120
|
|
111
|
-
|
112
|
-
|
121
|
+
assert_equal 2, h["items"].length
|
122
|
+
|
123
|
+
if es_version_2_x?
|
124
|
+
assert_bulk_create h["items"].first, "expected to create a book"
|
125
|
+
assert_bulk_delete h["items"].last, "expected to delete a book"
|
126
|
+
|
127
|
+
book_id2 = items.first["create"]["_id"]
|
128
|
+
elsif es_version_5_x?
|
129
|
+
assert_bulk_index h["items"].first, "expected to create a book"
|
130
|
+
assert_bulk_delete h["items"].last, "expected to delete a book"
|
131
|
+
|
132
|
+
book_id2 = items.first["index"]["_id"]
|
133
|
+
else
|
134
|
+
fail "Unknown ES version!"
|
135
|
+
end
|
113
136
|
|
114
|
-
book_id2 = items.first["create"]["_id"]
|
115
137
|
assert_match %r/^\S{20,22}$/, book_id2
|
116
138
|
|
117
139
|
@index.refresh
|
data/test/client/cluster_test.rb
CHANGED
@@ -27,19 +27,17 @@ describe Elastomer::Client::Cluster do
|
|
27
27
|
assert_instance_of Hash, h["metadata"], "the metadata are returned"
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
30
|
+
it "filters cluster state by metrics" do
|
31
|
+
h = @cluster.state(metrics: "nodes")
|
32
|
+
refute h.key("metadata"), "expected only nodes state"
|
33
|
+
h = @cluster.state(metrics: "metadata")
|
34
|
+
refute h.key("nodes"), "expected only metadata state"
|
35
|
+
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
37
|
+
it "filters cluster state by indices" do
|
38
|
+
@index.create(default_index_settings) unless @index.exists?
|
39
|
+
h = @cluster.state(metrics: "metadata", indices: @name)
|
40
|
+
assert [@name], h["metadata"]["indices"].keys
|
43
41
|
end
|
44
42
|
|
45
43
|
it "gets the cluster settings" do
|
@@ -55,13 +53,13 @@ describe Elastomer::Client::Cluster do
|
|
55
53
|
end
|
56
54
|
|
57
55
|
it "updates the cluster settings" do
|
58
|
-
@cluster.update_settings :
|
56
|
+
@cluster.update_settings transient: { "indices.ttl.interval" => "30m" }
|
59
57
|
h = @cluster.settings
|
60
58
|
|
61
59
|
value = h["transient"]["indices"]["ttl"]["interval"]
|
62
60
|
assert_equal "30m", value
|
63
61
|
|
64
|
-
@cluster.update_settings :
|
62
|
+
@cluster.update_settings transient: { "indices.ttl.interval" => "60m" }
|
65
63
|
h = @cluster.settings
|
66
64
|
|
67
65
|
value = h["transient"]["indices"]["ttl"]["interval"]
|
@@ -70,7 +68,9 @@ describe Elastomer::Client::Cluster do
|
|
70
68
|
|
71
69
|
it "returns cluster stats" do
|
72
70
|
h = @cluster.stats
|
73
|
-
|
71
|
+
expected = %w[cluster_name indices nodes status timestamp]
|
72
|
+
expected.unshift("_nodes") if es_version_5_x?
|
73
|
+
assert_equal expected, h.keys.sort
|
74
74
|
end
|
75
75
|
|
76
76
|
it "returns a list of pending tasks" do
|
@@ -80,7 +80,7 @@ describe Elastomer::Client::Cluster do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
it "returns the list of indices in the cluster" do
|
83
|
-
@index.create(
|
83
|
+
@index.create(default_index_settings) unless @index.exists?
|
84
84
|
indices = @cluster.indices
|
85
85
|
assert !indices.empty?, "expected to see an index"
|
86
86
|
end
|
@@ -94,7 +94,7 @@ describe Elastomer::Client::Cluster do
|
|
94
94
|
before do
|
95
95
|
@name = "elastomer-cluster-test"
|
96
96
|
@index = $client.index @name
|
97
|
-
@index.create(
|
97
|
+
@index.create(default_index_settings) unless @index.exists?
|
98
98
|
wait_for_index(@name)
|
99
99
|
end
|
100
100
|
|
@@ -104,12 +104,10 @@ describe Elastomer::Client::Cluster do
|
|
104
104
|
|
105
105
|
it "adds and gets an alias" do
|
106
106
|
hash = @cluster.get_aliases
|
107
|
-
|
108
|
-
assert_empty hash[@name]["aliases"]
|
109
|
-
end
|
107
|
+
assert_empty hash[@name]["aliases"]
|
110
108
|
|
111
109
|
@cluster.update_aliases \
|
112
|
-
:
|
110
|
+
add: {index: @name, alias: "elastomer-test-unikitty"}
|
113
111
|
|
114
112
|
hash = @cluster.get_aliases
|
115
113
|
assert_equal ["elastomer-test-unikitty"], hash[@name]["aliases"].keys
|
@@ -117,12 +115,10 @@ describe Elastomer::Client::Cluster do
|
|
117
115
|
|
118
116
|
it "adds and gets an alias with .aliases" do
|
119
117
|
hash = @cluster.aliases
|
120
|
-
|
121
|
-
assert_empty hash[@name]["aliases"]
|
122
|
-
end
|
118
|
+
assert_empty hash[@name]["aliases"]
|
123
119
|
|
124
120
|
@cluster.update_aliases \
|
125
|
-
:
|
121
|
+
add: {index: @name, alias: "elastomer-test-unikitty"}
|
126
122
|
|
127
123
|
hash = @cluster.aliases
|
128
124
|
assert_equal ["elastomer-test-unikitty"], hash[@name]["aliases"].keys
|
@@ -130,14 +126,14 @@ describe Elastomer::Client::Cluster do
|
|
130
126
|
|
131
127
|
it "removes an alias" do
|
132
128
|
@cluster.update_aliases \
|
133
|
-
:
|
129
|
+
add: {index: @name, alias: "elastomer-test-unikitty"}
|
134
130
|
|
135
131
|
hash = @cluster.get_aliases
|
136
132
|
assert_equal ["elastomer-test-unikitty"], hash[@name]["aliases"].keys
|
137
133
|
|
138
134
|
@cluster.update_aliases([
|
139
|
-
{:
|
140
|
-
{:
|
135
|
+
{add: {index: @name, alias: "elastomer-test-SpongeBob-SquarePants"}},
|
136
|
+
{remove: {index: @name, alias: "elastomer-test-unikitty"}}
|
141
137
|
])
|
142
138
|
|
143
139
|
hash = @cluster.get_aliases
|
@@ -145,12 +141,12 @@ describe Elastomer::Client::Cluster do
|
|
145
141
|
end
|
146
142
|
|
147
143
|
it "accepts the full aliases actions hash" do
|
148
|
-
@cluster.update_aliases :
|
149
|
-
{:
|
150
|
-
{:
|
144
|
+
@cluster.update_aliases actions: [
|
145
|
+
{add: {index: @name, alias: "elastomer-test-He-Man"}},
|
146
|
+
{add: {index: @name, alias: "elastomer-test-Skeletor"}}
|
151
147
|
]
|
152
148
|
|
153
|
-
hash = @cluster.get_aliases(:
|
149
|
+
hash = @cluster.get_aliases(index: @name)
|
154
150
|
assert_equal %w[elastomer-test-He-Man elastomer-test-Skeletor], hash[@name]["aliases"].keys.sort
|
155
151
|
end
|
156
152
|
end
|
data/test/client/docs_test.rb
CHANGED
@@ -270,13 +270,11 @@ describe Elastomer::Client::Docs do
|
|
270
270
|
end
|
271
271
|
|
272
272
|
it "supports the shards search API" do
|
273
|
-
|
274
|
-
h = @docs.search_shards(:type => "docs1")
|
273
|
+
h = @docs.search_shards(:type => "docs1")
|
275
274
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
end
|
275
|
+
assert h.key?("nodes"), "response contains \"nodes\" information"
|
276
|
+
assert h.key?("shards"), "response contains \"shards\" information"
|
277
|
+
assert h["shards"].is_a?(Array), "\"shards\" is an array"
|
280
278
|
end
|
281
279
|
|
282
280
|
it "generates QueryParsingError exceptions on bad input when searching" do
|
@@ -313,48 +311,6 @@ describe Elastomer::Client::Docs do
|
|
313
311
|
assert_equal 1, h["count"]
|
314
312
|
end
|
315
313
|
|
316
|
-
# The /_mlt endpoint has been removed from ES 2.X
|
317
|
-
if es_version_1_x?
|
318
|
-
it "searches for more like this" do
|
319
|
-
populate!
|
320
|
-
|
321
|
-
# for some reason, if there's no document indexed here all the mlt
|
322
|
-
# queries return zero results
|
323
|
-
@docs.index \
|
324
|
-
:_id => 3,
|
325
|
-
:_type => "doc1",
|
326
|
-
:title => "the author of faraday",
|
327
|
-
:author => "technoweenie"
|
328
|
-
|
329
|
-
@index.refresh
|
330
|
-
|
331
|
-
h = @docs.more_like_this({
|
332
|
-
:type => "doc1",
|
333
|
-
:id => 1,
|
334
|
-
:mlt_fields => "title",
|
335
|
-
:min_term_freq => 1
|
336
|
-
})
|
337
|
-
assert_equal 2, h["hits"]["total"]
|
338
|
-
|
339
|
-
h = @docs.more_like_this({
|
340
|
-
:facets => {
|
341
|
-
"author" => {
|
342
|
-
:terms => {
|
343
|
-
:field => "author"
|
344
|
-
}
|
345
|
-
}
|
346
|
-
}
|
347
|
-
}, {
|
348
|
-
:type => "doc1",
|
349
|
-
:id => 1,
|
350
|
-
:mlt_fields => "title,author",
|
351
|
-
:min_term_freq => 1
|
352
|
-
})
|
353
|
-
assert_equal 2, h["hits"]["total"]
|
354
|
-
assert_equal 2, h["facets"]["author"]["total"]
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
314
|
it "explains scoring" do
|
359
315
|
populate!
|
360
316
|
|
@@ -427,7 +383,7 @@ describe Elastomer::Client::Docs do
|
|
427
383
|
populate!(b)
|
428
384
|
end
|
429
385
|
|
430
|
-
|
386
|
+
assert_kind_of Integer, response["took"]
|
431
387
|
|
432
388
|
response = @docs.get(:id => 1, :type => "doc1")
|
433
389
|
assert_found response
|
data/test/client/index_test.rb
CHANGED
@@ -105,10 +105,6 @@ describe Elastomer::Client::Index do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it "updates document mappings" do
|
108
|
-
unless es_version_supports_update_mapping_with__all_disabled?
|
109
|
-
skip "Mapping Update API is broken in this ES version."
|
110
|
-
end
|
111
|
-
|
112
108
|
@index.create(
|
113
109
|
:mappings => {
|
114
110
|
:doco => {
|
@@ -136,10 +132,6 @@ describe Elastomer::Client::Index do
|
|
136
132
|
end
|
137
133
|
|
138
134
|
it "updates document mappings with .put_mapping" do
|
139
|
-
unless es_version_supports_update_mapping_with__all_disabled?
|
140
|
-
skip "Mapping Update API is broken in this ES version."
|
141
|
-
end
|
142
|
-
|
143
135
|
@index.create(
|
144
136
|
:mappings => {
|
145
137
|
:doco => {
|
@@ -166,71 +158,31 @@ describe Elastomer::Client::Index do
|
|
166
158
|
assert_property_exists @index.mapping[@name], "mux_mool", "song"
|
167
159
|
end
|
168
160
|
|
169
|
-
it "deletes document mappings" do
|
170
|
-
@index.create(
|
171
|
-
:mappings => {
|
172
|
-
:doco => {
|
173
|
-
:_source => { :enabled => false },
|
174
|
-
:_all => { :enabled => false },
|
175
|
-
:properties => {:title => { :type => "string", :analyzer => "standard" }}
|
176
|
-
}
|
177
|
-
}
|
178
|
-
)
|
179
|
-
assert_mapping_exists @index.mapping[@name], "doco"
|
180
|
-
|
181
|
-
response = @index.delete_mapping "doco"
|
182
|
-
|
183
|
-
if es_version_1_x?
|
184
|
-
assert_acknowledged response
|
185
|
-
|
186
|
-
mapping = @index.get_mapping
|
187
|
-
mapping = mapping[@name] if mapping.key? @name
|
188
|
-
mapping = mapping["mappings"] if mapping.key? "mappings"
|
189
|
-
|
190
|
-
assert_empty mapping, "no mappings are present"
|
191
|
-
|
192
|
-
elsif es_version_2_x?
|
193
|
-
assert_equal "No handler found for uri [/elastomer-index-test/doco] and method [DELETE]", response
|
194
|
-
|
195
|
-
else
|
196
|
-
assert false, "Unsupported Elasticsearch version #{$client.semantic_version}"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
161
|
it "lists all aliases to the index" do
|
201
162
|
@index.create(nil)
|
202
|
-
|
203
|
-
if es_version_always_returns_aliases?
|
204
|
-
assert_equal({@name => {"aliases" => {}}}, @index.get_aliases)
|
205
|
-
else
|
206
|
-
assert_equal({@name => {}}, @index.get_aliases)
|
207
|
-
end
|
163
|
+
assert_equal({@name => {"aliases" => {}}}, @index.get_aliases)
|
208
164
|
|
209
165
|
$client.cluster.update_aliases :add => {:index => @name, :alias => "foofaloo"}
|
210
166
|
assert_equal({@name => {"aliases" => {"foofaloo" => {}}}}, @index.get_aliases)
|
211
167
|
|
212
|
-
|
213
|
-
|
214
|
-
assert_equal({}, @index.get_alias("r*"))
|
215
|
-
end
|
168
|
+
assert_equal({@name => {"aliases" => {"foofaloo" => {}}}}, @index.get_alias("f*"))
|
169
|
+
assert_equal({}, @index.get_alias("r*"))
|
216
170
|
end
|
217
171
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
assert_empty @index.get_alias("*")
|
172
|
+
it "adds and deletes aliases to the index" do
|
173
|
+
@index.create(nil)
|
174
|
+
assert_empty @index.get_alias("*")
|
222
175
|
|
223
|
-
|
224
|
-
|
225
|
-
|
176
|
+
@index.add_alias "gondolin"
|
177
|
+
aliases = @index.get_alias("*")
|
178
|
+
assert_equal %w[gondolin], aliases[@name]["aliases"].keys.sort
|
226
179
|
|
227
|
-
|
228
|
-
|
229
|
-
|
180
|
+
@index.add_alias "gondor"
|
181
|
+
aliases = @index.get_alias("*")
|
182
|
+
assert_equal %w[gondolin gondor], aliases[@name]["aliases"].keys.sort
|
230
183
|
|
231
|
-
|
232
|
-
|
233
|
-
end
|
184
|
+
@index.delete_alias "gon*"
|
185
|
+
assert_empty @index.get_alias("*")
|
234
186
|
end
|
235
187
|
|
236
188
|
it "analyzes text and returns tokens" do
|
@@ -270,15 +222,11 @@ describe Elastomer::Client::Index do
|
|
270
222
|
before do
|
271
223
|
suggest = {
|
272
224
|
:type => "completion",
|
273
|
-
:
|
225
|
+
:analyzer => "simple",
|
274
226
|
:search_analyzer => "simple",
|
275
227
|
:payloads => false
|
276
228
|
}
|
277
229
|
|
278
|
-
if es_version_2_x?
|
279
|
-
suggest[:analyzer] = suggest.delete(:index_analyzer)
|
280
|
-
end
|
281
|
-
|
282
230
|
@index.create(
|
283
231
|
:settings => { :number_of_shards => 1, :number_of_replicas => 0 },
|
284
232
|
:mappings => {
|
@@ -327,14 +275,6 @@ describe Elastomer::Client::Index do
|
|
327
275
|
assert_equal 0, response["_shards"]["failed"]
|
328
276
|
end
|
329
277
|
|
330
|
-
# COMPATIBILITY ES 1.2 removed support for the gateway snapshot API.
|
331
|
-
if es_version_supports_gateway_snapshots?
|
332
|
-
it "snapshots" do
|
333
|
-
response = @index.snapshot
|
334
|
-
assert_equal 0, response["_shards"]["failed"]
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
278
|
it "recovery" do
|
339
279
|
response = @index.recovery
|
340
280
|
assert_includes response, "elastomer-index-test"
|
@@ -354,14 +294,6 @@ describe Elastomer::Client::Index do
|
|
354
294
|
end
|
355
295
|
end
|
356
296
|
|
357
|
-
# The /<index>/_status endpoint has been removed in ES 2.X
|
358
|
-
if es_version_1_x?
|
359
|
-
it "gets status" do
|
360
|
-
response = @index.status
|
361
|
-
assert_includes response["indices"], "elastomer-index-test"
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
297
|
it "gets segments" do
|
366
298
|
@index.docs("foo").index("foo" => "bar")
|
367
299
|
response = @index.segments
|