elastomer-client 0.9.0 → 2.0.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 +7 -1
- data/README.md +1 -1
- data/docs/client.md +5 -5
- data/docs/docs.md +6 -14
- data/docs/notifications.md +1 -1
- data/lib/elastomer/client/bulk.rb +2 -1
- data/lib/elastomer/client/docs.rb +6 -6
- data/lib/elastomer/client/errors.rb +8 -1
- data/lib/elastomer/client/index.rb +5 -1
- data/lib/elastomer/client/multi_search.rb +1 -1
- data/lib/elastomer/client/scroller.rb +6 -4
- data/lib/elastomer/version.rb +1 -1
- data/test/client/bulk_test.rb +3 -3
- data/test/client/cluster_test.rb +6 -15
- data/test/client/delete_by_query_test.rb +1 -1
- data/test/client/docs_test.rb +158 -188
- data/test/client/errors_test.rb +23 -0
- data/test/client/index_test.rb +58 -78
- data/test/client/multi_search_test.rb +5 -5
- data/test/client/percolator_test.rb +1 -1
- data/test/client/repository_test.rb +1 -1
- data/test/client/template_test.rb +10 -2
- data/test/client/warmer_test.rb +1 -1
- data/test/client_test.rb +10 -3
- data/test/test_helper.rb +13 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d77143e192594473f269fc69f9b6552dd7c5b3d8
|
4
|
+
data.tar.gz: aa71ccdf91b2a0277b61595bcd2b34409c3bd02b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7cb2962c8cdc9712989d9c2e127147e1126ca4f4dcca825c55b4a8f496626f01b236fd59097cb119f031849858f7f1acbe8eda4258e3f9dfa7d7e924533c011
|
7
|
+
data.tar.gz: d780635a018e9d178d28e279ee1051be21ecd522f6db0edcdb88ef53fbef49dc2b2de58433b9b96a1bb13fb773177830487a0f7bbc3e2cd439eb511af6e56268
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/docs/client.md
CHANGED
@@ -182,12 +182,12 @@ client.expand_path("{/index}{/type}/_search", {
|
|
182
182
|
#=> "/twitter/tweet/_search?q=*:*"
|
183
183
|
|
184
184
|
client.expand_path("{/index}{/type}/_search", {
|
185
|
-
:index
|
186
|
-
:type
|
187
|
-
:q
|
188
|
-
:
|
185
|
+
:index => "twitter",
|
186
|
+
:type => ["tweet", "user"],
|
187
|
+
:q => "*:*"
|
188
|
+
:size => 0
|
189
189
|
})
|
190
|
-
#=> "/twitter/tweet,user/_search?q=*:*&
|
190
|
+
#=> "/twitter/tweet,user/_search?q=*:*&size=0"
|
191
191
|
```
|
192
192
|
|
193
193
|
In the examples above the path elements are optional. We can force them to be
|
data/docs/docs.md
CHANGED
@@ -196,27 +196,19 @@ results["hits"]["total"] #=> 1
|
|
196
196
|
```
|
197
197
|
|
198
198
|
The search results always contain the total number of matched documents; even if
|
199
|
-
the `:size` is set to zero or some other number.
|
199
|
+
the `:size` is set to zero or some other number.
|
200
200
|
|
201
201
|
Elasticsearch provides specific methods for obtaining the number of documents
|
202
|
-
that match a search.
|
203
|
-
|
202
|
+
that match a search. Using the count API endpoint is another way to get the
|
203
|
+
number of documents.
|
204
204
|
|
205
205
|
```ruby
|
206
|
-
results = client.docs("blog", "post").
|
207
|
-
:q => "title:nerd"
|
208
|
-
:search_type => "count"
|
206
|
+
results = client.docs("blog", "post").count \
|
207
|
+
:q => "title:nerd"
|
209
208
|
|
210
|
-
results["
|
209
|
+
results["count"] #=> 1
|
211
210
|
```
|
212
211
|
|
213
|
-
The `"count"` search type is much more efficient then setting the size to zero.
|
214
|
-
These count queries will return more quickly and consume less memory inside
|
215
|
-
Elasticsearch.
|
216
|
-
|
217
|
-
There is also a `count` API method, but the `:search_type` approach is even more
|
218
|
-
efficient than the count API.
|
219
|
-
|
220
212
|
#### Deleting
|
221
213
|
|
222
214
|
Documents can be deleted directly given their document ID.
|
data/docs/notifications.md
CHANGED
@@ -14,7 +14,7 @@ The event namespace is `request.client.elastomer`.
|
|
14
14
|
:action => "docs.search",
|
15
15
|
:context => nil,
|
16
16
|
:body => "{\"query\":{\"match_all\":{}}}",
|
17
|
-
:url => #<URI::HTTP:0x007fb6f3e98b60 URL:http://localhost:19200/index-test/_search?
|
17
|
+
:url => #<URI::HTTP:0x007fb6f3e98b60 URL:http://localhost:19200/index-test/_search?size=0>,
|
18
18
|
:method => :get,
|
19
19
|
:status => 200
|
20
20
|
}
|
@@ -158,6 +158,7 @@ module Elastomer
|
|
158
158
|
# immediately.
|
159
159
|
#
|
160
160
|
class Bulk
|
161
|
+
DEFAULT_REQUEST_SIZE = 10 * 2**20 # 10 MB
|
161
162
|
|
162
163
|
# Create a new bulk client for handling some of the details of
|
163
164
|
# accumulating documents to index and then formatting them properly for
|
@@ -174,7 +175,7 @@ module Elastomer
|
|
174
175
|
@actions = []
|
175
176
|
@current_request_size = 0
|
176
177
|
@current_action_count = 0
|
177
|
-
self.request_size = params.delete(:request_size)
|
178
|
+
self.request_size = params.delete(:request_size) || DEFAULT_REQUEST_SIZE
|
178
179
|
self.action_count = params.delete(:action_count)
|
179
180
|
end
|
180
181
|
|
@@ -331,11 +331,11 @@ module Elastomer
|
|
331
331
|
Percolate
|
332
332
|
=end
|
333
333
|
|
334
|
-
#
|
335
|
-
#
|
336
|
-
#
|
337
|
-
#
|
338
|
-
# allowed.
|
334
|
+
# Deprecated - use the More Like This query: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl-mlt-query.html
|
335
|
+
# Search for documents similar to a specific document. The
|
336
|
+
# document :id is provided as part of the params hash. If the _all field
|
337
|
+
# is not enabled, :mlt_fields must be passed. A query cannot be present in
|
338
|
+
# the query body, but other fields like :size and :facets are allowed.
|
339
339
|
#
|
340
340
|
# params - Parameters Hash
|
341
341
|
# :id - the ID of the document
|
@@ -504,7 +504,7 @@ Percolate
|
|
504
504
|
# Examples
|
505
505
|
#
|
506
506
|
# docs.multi_search do |m|
|
507
|
-
# m.search({:query => {:match_all => {}}, :
|
507
|
+
# m.search({:query => {:match_all => {}}, :size => 0)
|
508
508
|
# m.search({:query => {:field => {"foo" => "bar"}}})
|
509
509
|
# ...
|
510
510
|
# end
|
@@ -17,6 +17,7 @@ module Elastomer
|
|
17
17
|
#
|
18
18
|
def initialize( *args )
|
19
19
|
@status = nil
|
20
|
+
@error = nil
|
20
21
|
|
21
22
|
case args.first
|
22
23
|
when Exception
|
@@ -27,9 +28,11 @@ module Elastomer
|
|
27
28
|
when Faraday::Response
|
28
29
|
response = args.shift
|
29
30
|
@status = response.status
|
31
|
+
|
30
32
|
body = response.body
|
33
|
+
@error = body["error"] if body.is_a?(Hash) && body.key?("error")
|
31
34
|
|
32
|
-
message =
|
35
|
+
message = @error || body.to_s
|
33
36
|
super message
|
34
37
|
|
35
38
|
else
|
@@ -41,6 +44,10 @@ module Elastomer
|
|
41
44
|
# created with a response.
|
42
45
|
attr_reader :status
|
43
46
|
|
47
|
+
# Returns the Elasticsearch error from the `response` or nil if the Error
|
48
|
+
# was not created with a response.
|
49
|
+
attr_reader :error
|
50
|
+
|
44
51
|
# Indicates that the error is fatal. The request should not be tried
|
45
52
|
# again.
|
46
53
|
def fatal?
|
@@ -150,6 +150,10 @@ module Elastomer
|
|
150
150
|
end
|
151
151
|
alias_method :put_mapping, :update_mapping
|
152
152
|
|
153
|
+
# DEPRECATED: It is no longer possible to delete the mapping for a type.
|
154
|
+
# Instead you should delete the index and recreate it with new mappings.
|
155
|
+
# See https://www.elastic.co/guide/en/elasticsearch/reference/2.3/indices-delete-mapping.html
|
156
|
+
#
|
153
157
|
# Delete the mapping identified by `type`. This deletes all documents of
|
154
158
|
# that type from the index.
|
155
159
|
#
|
@@ -500,7 +504,7 @@ module Elastomer
|
|
500
504
|
# Examples
|
501
505
|
#
|
502
506
|
# index.multi_search do |m|
|
503
|
-
# m.search({:query => {:match_all => {}}, :
|
507
|
+
# m.search({:query => {:match_all => {}}, :size => 0)
|
504
508
|
# m.search({:query => {:field => {"author" => "grantr"}}}, :type => 'tweet')
|
505
509
|
# ...
|
506
510
|
# end
|
@@ -25,7 +25,7 @@ module Elastomer
|
|
25
25
|
#
|
26
26
|
# # block form
|
27
27
|
# multi_search(:index => 'default-index') do |m|
|
28
|
-
# m.search({:query => {:match_all => {}}, :
|
28
|
+
# m.search({:query => {:match_all => {}}, :size => 0)
|
29
29
|
# m.search({:query => {:field => {"foo" => "bar"}}}, :type => 'default-type')
|
30
30
|
# ...
|
31
31
|
# end
|
@@ -23,6 +23,8 @@ module Elastomer
|
|
23
23
|
Scroller.new(self, query, opts)
|
24
24
|
end
|
25
25
|
|
26
|
+
# DEPRECATED in ES 2.1.0 - use a Scroll query sorted by _doc: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-search-type.html#scan
|
27
|
+
#
|
26
28
|
# Create a new Scroller instance for scrolling all results from a `query`
|
27
29
|
# via "scan" semantics.
|
28
30
|
#
|
@@ -56,7 +58,7 @@ module Elastomer
|
|
56
58
|
# :type - the document type to search
|
57
59
|
# :scroll - the keep alive time of the scrolling request (5 minutes by default)
|
58
60
|
# :size - the number of documents per shard to fetch per scroll
|
59
|
-
# :search_type - set to 'scan' for scan semantics
|
61
|
+
# :search_type - set to 'scan' for scan semantics # DEPRECATED in ES 2.1.0 - use a Scroll query sorted by _doc: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-search-type.html#scan
|
60
62
|
#
|
61
63
|
# Examples
|
62
64
|
#
|
@@ -85,7 +87,7 @@ module Elastomer
|
|
85
87
|
#
|
86
88
|
# Examples
|
87
89
|
#
|
88
|
-
# scroll_id = client.start_scroll('{"query":{"match_all":{}}}', :index => 'test'
|
90
|
+
# scroll_id = client.start_scroll('{"query":{"match_all":{}}}', :index => 'test')['_scroll_id']
|
89
91
|
#
|
90
92
|
# h = client.continue_scroll scroll_id # scroll to get the next set of results
|
91
93
|
# scroll_id = h['_scroll_id'] # and store the scroll_id to use later
|
@@ -123,11 +125,11 @@ module Elastomer
|
|
123
125
|
# :type - the document type to search
|
124
126
|
# :scroll - the keep alive time of the scrolling request (5 minutes by default)
|
125
127
|
# :size - the number of documents per shard to fetch per scroll
|
126
|
-
# :search_type - set to 'scan' for scan query
|
128
|
+
# :search_type - set to 'scan' for scan semantics # DEPRECATED in ES 2.1.0 - use a Scroll query sorted by _doc: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-search-type.html#scan
|
127
129
|
#
|
128
130
|
# Examples
|
129
131
|
#
|
130
|
-
# scan = Scroller.new(client, {:
|
132
|
+
# scan = Scroller.new(client, {:query => {:match_all => {}}}, :index => 'test-1')
|
131
133
|
# scan.each_document { |doc|
|
132
134
|
# doc['_id']
|
133
135
|
# doc['_source']
|
data/lib/elastomer/version.rb
CHANGED
data/test/client/bulk_test.rb
CHANGED
@@ -188,7 +188,7 @@ describe Elastomer::Client::Bulk do
|
|
188
188
|
ary.each { |a| a["items"].each { |b| assert_bulk_index(b) } }
|
189
189
|
|
190
190
|
@index.refresh
|
191
|
-
h = @index.docs.search :q => "*:*", :
|
191
|
+
h = @index.docs.search :q => "*:*", :size => 0
|
192
192
|
|
193
193
|
assert_equal 10, h["hits"]["total"]
|
194
194
|
end
|
@@ -219,7 +219,7 @@ describe Elastomer::Client::Bulk do
|
|
219
219
|
ary.each { |a| a["items"].each { |b| assert_bulk_index(b) } }
|
220
220
|
|
221
221
|
@index.refresh
|
222
|
-
h = @index.docs.search :q => "*:*", :
|
222
|
+
h = @index.docs.search :q => "*:*", :size => 0
|
223
223
|
|
224
224
|
assert_equal 10, h["hits"]["total"]
|
225
225
|
end
|
@@ -314,7 +314,7 @@ describe Elastomer::Client::Bulk do
|
|
314
314
|
[:index, { :message => "tweet 3" }, { :_id => 3, :_type => "book", :_index => @index.name }]
|
315
315
|
]
|
316
316
|
items = []
|
317
|
-
|
317
|
+
$client.bulk_stream_items(ops, { :action_count => 2 }) { |item| items << item }
|
318
318
|
assert_equal(3, items.length)
|
319
319
|
assert_bulk_index(items[0])
|
320
320
|
assert_bulk_index(items[1])
|
data/test/client/cluster_test.rb
CHANGED
@@ -55,26 +55,17 @@ describe Elastomer::Client::Cluster do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "updates the cluster settings" do
|
58
|
-
@cluster.update_settings :transient => { "indices.ttl.interval" => "
|
58
|
+
@cluster.update_settings :transient => { "indices.ttl.interval" => "30m" }
|
59
59
|
h = @cluster.settings
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
# expand nested properties, e.g.
|
64
|
-
# {"indices.ttl.interval": "30"} changed to
|
65
|
-
# {"indices": {"ttl": {"interval":"30"}}}
|
61
|
+
value = h["transient"]["indices"]["ttl"]["interval"]
|
62
|
+
assert_equal "30m", value
|
66
63
|
|
67
|
-
|
68
|
-
value = h["transient"]["indices.ttl.interval"] ||
|
69
|
-
h["transient"]["indices"]["ttl"]["interval"]
|
70
|
-
assert_equal "30", value
|
71
|
-
|
72
|
-
@cluster.update_settings :transient => { "indices.ttl.interval" => "60" }
|
64
|
+
@cluster.update_settings :transient => { "indices.ttl.interval" => "60m" }
|
73
65
|
h = @cluster.settings
|
74
66
|
|
75
|
-
value = h["transient"]["indices
|
76
|
-
|
77
|
-
assert_equal "60", value
|
67
|
+
value = h["transient"]["indices"]["ttl"]["interval"]
|
68
|
+
assert_equal "60m", value
|
78
69
|
end
|
79
70
|
|
80
71
|
it "returns cluster stats" do
|
data/test/client/docs_test.rb
CHANGED
@@ -13,7 +13,7 @@ describe Elastomer::Client::Docs do
|
|
13
13
|
:doc1 => {
|
14
14
|
:_source => { :enabled => true }, :_all => { :enabled => false },
|
15
15
|
:properties => {
|
16
|
-
:title => { :type => "string", :analyzer => "standard" },
|
16
|
+
:title => { :type => "string", :analyzer => "standard", :term_vector => "with_positions_offsets" },
|
17
17
|
:author => { :type => "string", :index => "not_analyzed" }
|
18
18
|
}
|
19
19
|
},
|
@@ -233,25 +233,18 @@ describe Elastomer::Client::Docs do
|
|
233
233
|
assert_found h["docs"][0]
|
234
234
|
refute_found h["docs"][1]
|
235
235
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
if es_version_1_x?
|
242
|
-
h = @docs.delete_by_query(
|
243
|
-
:query => {
|
244
|
-
:filtered => {
|
245
|
-
:query => {:match_all => {}},
|
246
|
-
:filter => {:term => {:author => "pea53"}}
|
247
|
-
}
|
236
|
+
h = @docs.delete_by_query(
|
237
|
+
:query => {
|
238
|
+
:filtered => {
|
239
|
+
:query => {:match_all => {}},
|
240
|
+
:filter => {:term => {:author => "pea53"}}
|
248
241
|
}
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
242
|
+
}
|
243
|
+
)
|
244
|
+
@index.refresh
|
245
|
+
h = @docs.multi_get :ids => [1, 2]
|
246
|
+
refute_found h["docs"][0]
|
247
|
+
refute_found h["docs"][1]
|
255
248
|
end
|
256
249
|
|
257
250
|
it "searches for documents" do
|
@@ -301,66 +294,57 @@ describe Elastomer::Client::Docs do
|
|
301
294
|
h = @docs.count :q => "*:*", :type => "doc1,doc2"
|
302
295
|
assert_equal 4, h["count"]
|
303
296
|
|
304
|
-
|
305
|
-
|
306
|
-
# This broke compatibility with the ES 0.90 count api.
|
307
|
-
if es_version_1_x?
|
308
|
-
h = @docs.count({
|
309
|
-
:query => {
|
310
|
-
:filtered => {
|
311
|
-
:query => {:match_all => {}},
|
312
|
-
:filter => {:term => {:author => "defunkt"}}
|
313
|
-
}
|
314
|
-
}
|
315
|
-
}, :type => %w[doc1 doc2] )
|
316
|
-
else
|
317
|
-
h = @docs.count({
|
297
|
+
h = @docs.count({
|
298
|
+
:query => {
|
318
299
|
:filtered => {
|
319
300
|
:query => {:match_all => {}},
|
320
301
|
:filter => {:term => {:author => "defunkt"}}
|
321
302
|
}
|
322
|
-
}
|
323
|
-
|
303
|
+
}
|
304
|
+
}, :type => %w[doc1 doc2] )
|
324
305
|
assert_equal 1, h["count"]
|
325
306
|
end
|
326
307
|
|
327
|
-
|
328
|
-
|
308
|
+
# The /_mlt endpoint has been removed from ES 2.X
|
309
|
+
if es_version_1_x?
|
310
|
+
it "searches for more like this" do
|
311
|
+
populate!
|
329
312
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
313
|
+
# for some reason, if there's no document indexed here all the mlt
|
314
|
+
# queries return zero results
|
315
|
+
@docs.index \
|
316
|
+
:_id => 3,
|
317
|
+
:_type => "doc1",
|
318
|
+
:title => "the author of faraday",
|
319
|
+
:author => "technoweenie"
|
337
320
|
|
338
|
-
|
321
|
+
@index.refresh
|
339
322
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
323
|
+
h = @docs.more_like_this({
|
324
|
+
:type => "doc1",
|
325
|
+
:id => 1,
|
326
|
+
:mlt_fields => "title",
|
327
|
+
:min_term_freq => 1
|
328
|
+
})
|
329
|
+
assert_equal 2, h["hits"]["total"]
|
347
330
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
331
|
+
h = @docs.more_like_this({
|
332
|
+
:facets => {
|
333
|
+
"author" => {
|
334
|
+
:terms => {
|
335
|
+
:field => "author"
|
336
|
+
}
|
353
337
|
}
|
354
338
|
}
|
355
|
-
}
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
339
|
+
}, {
|
340
|
+
:type => "doc1",
|
341
|
+
:id => 1,
|
342
|
+
:mlt_fields => "title,author",
|
343
|
+
:min_term_freq => 1
|
344
|
+
})
|
345
|
+
assert_equal 2, h["hits"]["total"]
|
346
|
+
assert_equal 2, h["facets"]["author"]["total"]
|
347
|
+
end
|
364
348
|
end
|
365
349
|
|
366
350
|
it "explains scoring" do
|
@@ -385,26 +369,14 @@ describe Elastomer::Client::Docs do
|
|
385
369
|
h = @docs.validate :q => "*:*"
|
386
370
|
assert_equal true, h["valid"]
|
387
371
|
|
388
|
-
|
389
|
-
|
390
|
-
# This broke compatibility with the ES 0.90 validate api.
|
391
|
-
if es_version_1_x?
|
392
|
-
h = @docs.validate({
|
393
|
-
:query => {
|
394
|
-
:filtered => {
|
395
|
-
:query => {:match_all => {}},
|
396
|
-
:filter => {:term => {:author => "defunkt"}}
|
397
|
-
}
|
398
|
-
}
|
399
|
-
}, :type => %w[doc1 doc2] )
|
400
|
-
else
|
401
|
-
h = @docs.validate({
|
372
|
+
h = @docs.validate({
|
373
|
+
:query => {
|
402
374
|
:filtered => {
|
403
375
|
:query => {:match_all => {}},
|
404
376
|
:filter => {:term => {:author => "defunkt"}}
|
405
377
|
}
|
406
|
-
}
|
407
|
-
|
378
|
+
}
|
379
|
+
}, :type => %w[doc1 doc2] )
|
408
380
|
assert_equal true, h["valid"]
|
409
381
|
end
|
410
382
|
|
@@ -454,144 +426,142 @@ describe Elastomer::Client::Docs do
|
|
454
426
|
assert_equal "mojombo", response["_source"]["author"]
|
455
427
|
end
|
456
428
|
|
457
|
-
|
458
|
-
|
459
|
-
populate!
|
460
|
-
|
461
|
-
response = @docs.termvector :type => "doc2", :id => 1, :fields => "title"
|
429
|
+
it "provides access to term vector statistics" do
|
430
|
+
populate!
|
462
431
|
|
463
|
-
|
464
|
-
assert response["term_vectors"]["title"]["field_statistics"]
|
465
|
-
assert response["term_vectors"]["title"]["terms"]
|
466
|
-
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
467
|
-
end
|
432
|
+
response = @docs.termvector :type => "doc2", :id => 1, :fields => "title"
|
468
433
|
|
469
|
-
|
470
|
-
|
434
|
+
assert response["term_vectors"]["title"]
|
435
|
+
assert response["term_vectors"]["title"]["field_statistics"]
|
436
|
+
assert response["term_vectors"]["title"]["terms"]
|
437
|
+
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
438
|
+
end
|
471
439
|
|
472
|
-
|
440
|
+
it "provides access to term vector statistics with .termvectors" do
|
441
|
+
populate!
|
473
442
|
|
474
|
-
|
475
|
-
assert response["term_vectors"]["title"]["field_statistics"]
|
476
|
-
assert response["term_vectors"]["title"]["terms"]
|
477
|
-
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
478
|
-
end
|
443
|
+
response = @docs.termvectors :type => "doc2", :id => 1, :fields => "title"
|
479
444
|
|
480
|
-
|
481
|
-
|
445
|
+
assert response["term_vectors"]["title"]
|
446
|
+
assert response["term_vectors"]["title"]["field_statistics"]
|
447
|
+
assert response["term_vectors"]["title"]["terms"]
|
448
|
+
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
449
|
+
end
|
482
450
|
|
483
|
-
|
451
|
+
it "provides access to term vector statistics with .term_vector" do
|
452
|
+
populate!
|
484
453
|
|
485
|
-
|
486
|
-
assert response["term_vectors"]["title"]["field_statistics"]
|
487
|
-
assert response["term_vectors"]["title"]["terms"]
|
488
|
-
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
489
|
-
end
|
454
|
+
response = @docs.term_vector :type => "doc2", :id => 1, :fields => "title"
|
490
455
|
|
491
|
-
|
492
|
-
|
456
|
+
assert response["term_vectors"]["title"]
|
457
|
+
assert response["term_vectors"]["title"]["field_statistics"]
|
458
|
+
assert response["term_vectors"]["title"]["terms"]
|
459
|
+
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
460
|
+
end
|
493
461
|
|
494
|
-
|
462
|
+
it "provides access to term vector statistics with .term_vectors" do
|
463
|
+
populate!
|
495
464
|
|
496
|
-
|
497
|
-
assert response["term_vectors"]["title"]["field_statistics"]
|
498
|
-
assert response["term_vectors"]["title"]["terms"]
|
499
|
-
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
500
|
-
end
|
465
|
+
response = @docs.term_vectors :type => "doc2", :id => 1, :fields => "title"
|
501
466
|
|
502
|
-
|
503
|
-
|
467
|
+
assert response["term_vectors"]["title"]
|
468
|
+
assert response["term_vectors"]["title"]["field_statistics"]
|
469
|
+
assert response["term_vectors"]["title"]["terms"]
|
470
|
+
assert_equal %w[author logging of the], response["term_vectors"]["title"]["terms"].keys
|
471
|
+
end
|
504
472
|
|
505
|
-
|
506
|
-
|
473
|
+
it "provides access to multi term vector statistics" do
|
474
|
+
populate!
|
507
475
|
|
508
|
-
|
509
|
-
|
510
|
-
end
|
476
|
+
response = @docs.multi_termvectors({:ids => [1, 2]}, :type => "doc2", :fields => "title", :term_statistics => true)
|
477
|
+
docs = response["docs"]
|
511
478
|
|
512
|
-
|
513
|
-
|
479
|
+
assert docs
|
480
|
+
assert_equal(%w[1 2], docs.map { |h| h["_id"] }.sort)
|
481
|
+
end
|
514
482
|
|
515
|
-
|
516
|
-
|
483
|
+
it "provides access to multi term vector statistics with .multi_term_vectors" do
|
484
|
+
populate!
|
517
485
|
|
518
|
-
|
519
|
-
|
520
|
-
end
|
486
|
+
response = @docs.multi_term_vectors({:ids => [1, 2]}, :type => "doc2", :fields => "title", :term_statistics => true)
|
487
|
+
docs = response["docs"]
|
521
488
|
|
522
|
-
|
523
|
-
|
489
|
+
assert docs
|
490
|
+
assert_equal(%w[1 2], docs.map { |h| h["_id"] }.sort)
|
491
|
+
end
|
524
492
|
|
525
|
-
|
526
|
-
|
527
|
-
assert response["created"], "Couldn't create the percolator query"
|
528
|
-
percolator2 = @index.percolator "2"
|
529
|
-
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
530
|
-
assert response["created"], "Couldn't create the percolator query"
|
493
|
+
it "percolates a given document" do
|
494
|
+
populate!
|
531
495
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
496
|
+
percolator1 = @index.percolator "1"
|
497
|
+
response = percolator1.create :query => { :match => { :author => "pea53" } }
|
498
|
+
assert response["created"], "Couldn't create the percolator query"
|
499
|
+
percolator2 = @index.percolator "2"
|
500
|
+
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
501
|
+
assert response["created"], "Couldn't create the percolator query"
|
536
502
|
|
537
|
-
|
538
|
-
|
503
|
+
response = @index.docs("doc1").percolate(:doc => { :author => "pea53" })
|
504
|
+
assert_equal 1, response["matches"].length
|
505
|
+
assert_equal "1", response["matches"][0]["_id"]
|
506
|
+
end
|
539
507
|
|
540
|
-
|
541
|
-
|
542
|
-
assert response["created"], "Couldn't create the percolator query"
|
543
|
-
percolator2 = @index.percolator "2"
|
544
|
-
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
545
|
-
assert response["created"], "Couldn't create the percolator query"
|
508
|
+
it "percolates an existing document" do
|
509
|
+
populate!
|
546
510
|
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
511
|
+
percolator1 = @index.percolator "1"
|
512
|
+
response = percolator1.create :query => { :match => { :author => "pea53" } }
|
513
|
+
assert response["created"], "Couldn't create the percolator query"
|
514
|
+
percolator2 = @index.percolator "2"
|
515
|
+
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
516
|
+
assert response["created"], "Couldn't create the percolator query"
|
551
517
|
|
552
|
-
|
553
|
-
|
518
|
+
response = @index.docs("doc2").percolate(nil, :id => "1")
|
519
|
+
assert_equal 1, response["matches"].length
|
520
|
+
assert_equal "1", response["matches"][0]["_id"]
|
521
|
+
end
|
554
522
|
|
555
|
-
|
556
|
-
|
557
|
-
assert response["created"], "Couldn't create the percolator query"
|
558
|
-
percolator2 = @index.percolator "2"
|
559
|
-
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
560
|
-
assert response["created"], "Couldn't create the percolator query"
|
523
|
+
it "counts the matches for percolating a given document" do
|
524
|
+
populate!
|
561
525
|
|
562
|
-
|
563
|
-
|
564
|
-
|
526
|
+
percolator1 = @index.percolator "1"
|
527
|
+
response = percolator1.create :query => { :match => { :author => "pea53" } }
|
528
|
+
assert response["created"], "Couldn't create the percolator query"
|
529
|
+
percolator2 = @index.percolator "2"
|
530
|
+
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
531
|
+
assert response["created"], "Couldn't create the percolator query"
|
565
532
|
|
566
|
-
|
567
|
-
|
533
|
+
count = @index.docs("doc1").percolate_count :doc => { :author => "pea53" }
|
534
|
+
assert_equal 1, count
|
535
|
+
end
|
568
536
|
|
569
|
-
|
570
|
-
|
571
|
-
assert response["created"], "Couldn't create the percolator query"
|
572
|
-
percolator2 = @index.percolator "2"
|
573
|
-
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
574
|
-
assert response["created"], "Couldn't create the percolator query"
|
537
|
+
it "counts the matches for percolating an existing document" do
|
538
|
+
populate!
|
575
539
|
|
576
|
-
|
577
|
-
|
578
|
-
|
540
|
+
percolator1 = @index.percolator "1"
|
541
|
+
response = percolator1.create :query => { :match => { :author => "pea53" } }
|
542
|
+
assert response["created"], "Couldn't create the percolator query"
|
543
|
+
percolator2 = @index.percolator "2"
|
544
|
+
response = percolator2.create :query => { :match => { :author => "defunkt" } }
|
545
|
+
assert response["created"], "Couldn't create the percolator query"
|
579
546
|
|
580
|
-
|
581
|
-
|
582
|
-
|
547
|
+
count = @index.docs("doc2").percolate_count(nil, :id => "1")
|
548
|
+
assert_equal 1, count
|
549
|
+
end
|
583
550
|
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
m.count({}, { :author => "grantr" })
|
588
|
-
end
|
551
|
+
it "performs multi percolate queries" do
|
552
|
+
@index.percolator("1").create :query => { :match_all => { } }
|
553
|
+
@index.percolator("2").create :query => { :match => { :author => "pea53" } }
|
589
554
|
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
555
|
+
h = @index.docs("doc2").multi_percolate do |m|
|
556
|
+
m.percolate :author => "pea53"
|
557
|
+
m.percolate :author => "grantr"
|
558
|
+
m.count({}, { :author => "grantr" })
|
594
559
|
end
|
560
|
+
|
561
|
+
response1, response2, response3 = h["responses"]
|
562
|
+
assert_equal ["1", "2"], response1["matches"].map { |match| match["_id"] }.sort
|
563
|
+
assert_equal ["1"], response2["matches"].map { |match| match["_id"] }.sort
|
564
|
+
assert_equal 1, response3["total"]
|
595
565
|
end
|
596
566
|
|
597
567
|
# Create/index multiple documents.
|
data/test/client/errors_test.rb
CHANGED
@@ -15,6 +15,29 @@ describe Elastomer::Client::Error do
|
|
15
15
|
response = Faraday::Response.new(:body => {"error" => "IndexMissingException"})
|
16
16
|
err = Elastomer::Client::Error.new(response)
|
17
17
|
assert_equal "IndexMissingException", err.message
|
18
|
+
assert_equal "IndexMissingException", err.error
|
19
|
+
|
20
|
+
body = {
|
21
|
+
"error" => {
|
22
|
+
"index" => "non-existent-index",
|
23
|
+
"reason" => "no such index",
|
24
|
+
"resource.id" => "non-existent-index",
|
25
|
+
"resource.type" => "index_or_alias",
|
26
|
+
"root_cause"=> [{
|
27
|
+
"index" => "non-existent-index",
|
28
|
+
"reason" => "no such index",
|
29
|
+
"resource.id" => "non-existent-index",
|
30
|
+
"resource.type" => "index_or_alias",
|
31
|
+
"type" => "index_not_found_exception"
|
32
|
+
}],
|
33
|
+
"type" => "index_not_found_exception"
|
34
|
+
},
|
35
|
+
"status" => 404
|
36
|
+
}
|
37
|
+
response = Faraday::Response.new(:body => body)
|
38
|
+
err = Elastomer::Client::Error.new(response)
|
39
|
+
assert_equal body["error"].to_s, err.message
|
40
|
+
assert_equal body["error"], err.error
|
18
41
|
end
|
19
42
|
|
20
43
|
it "is instantiated from another exception" do
|
data/test/client/index_test.rb
CHANGED
@@ -35,38 +35,16 @@ describe Elastomer::Client::Index do
|
|
35
35
|
@index.create :settings => { :number_of_shards => 3, :number_of_replicas => 0 }
|
36
36
|
settings = @index.get_settings[@name]["settings"]
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
# expand nested properties, e.g.
|
41
|
-
# {"index.number_of_replicas": "1"} changed to
|
42
|
-
# {"index": {"number_of_replicas":"1"}}
|
43
|
-
|
44
|
-
# To support both versions, we check for either return format.
|
45
|
-
value = settings["index.number_of_shards"] ||
|
46
|
-
settings["index"]["number_of_shards"]
|
47
|
-
assert_equal "3", value
|
48
|
-
value = settings["index.number_of_replicas"] ||
|
49
|
-
settings["index"]["number_of_replicas"]
|
50
|
-
assert_equal "0", value
|
38
|
+
assert_equal "3", settings["index"]["number_of_shards"]
|
39
|
+
assert_equal "0", settings["index"]["number_of_replicas"]
|
51
40
|
end
|
52
41
|
|
53
42
|
it "creates an index with settings with .settings" do
|
54
43
|
@index.create :settings => { :number_of_shards => 3, :number_of_replicas => 0 }
|
55
44
|
settings = @index.settings[@name]["settings"]
|
56
45
|
|
57
|
-
|
58
|
-
|
59
|
-
# expand nested properties, e.g.
|
60
|
-
# {"index.number_of_replicas": "1"} changed to
|
61
|
-
# {"index": {"number_of_replicas":"1"}}
|
62
|
-
|
63
|
-
# To support both versions, we check for either return format.
|
64
|
-
value = settings["index.number_of_shards"] ||
|
65
|
-
settings["index"]["number_of_shards"]
|
66
|
-
assert_equal "3", value
|
67
|
-
value = settings["index.number_of_replicas"] ||
|
68
|
-
settings["index"]["number_of_replicas"]
|
69
|
-
assert_equal "0", value
|
46
|
+
assert_equal "3", settings["index"]["number_of_shards"]
|
47
|
+
assert_equal "0", settings["index"]["number_of_replicas"]
|
70
48
|
end
|
71
49
|
|
72
50
|
it "adds mappings for document types" do
|
@@ -201,13 +179,22 @@ describe Elastomer::Client::Index do
|
|
201
179
|
assert_mapping_exists @index.mapping[@name], "doco"
|
202
180
|
|
203
181
|
response = @index.delete_mapping "doco"
|
204
|
-
assert_acknowledged response
|
205
182
|
|
206
|
-
|
207
|
-
|
208
|
-
|
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"
|
209
191
|
|
210
|
-
|
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
|
211
198
|
end
|
212
199
|
|
213
200
|
it "lists all aliases to the index" do
|
@@ -246,48 +233,45 @@ describe Elastomer::Client::Index do
|
|
246
233
|
end
|
247
234
|
end
|
248
235
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
tokens = @index.analyze "Just a few words to analyze.", :analyzer => "standard", :index => nil
|
254
|
-
tokens = tokens["tokens"].map { |h| h["token"] }
|
255
|
-
assert_equal %w[just a few words to analyze], tokens
|
236
|
+
it "analyzes text and returns tokens" do
|
237
|
+
tokens = @index.analyze "Just a few words to analyze.", :analyzer => "standard", :index => nil
|
238
|
+
tokens = tokens["tokens"].map { |h| h["token"] }
|
239
|
+
assert_equal %w[just a few words to analyze], tokens
|
256
240
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
}
|
241
|
+
@index.create(
|
242
|
+
:settings => {
|
243
|
+
:number_of_shards => 1,
|
244
|
+
:number_of_replicas => 0,
|
245
|
+
:analysis => {
|
246
|
+
:analyzer => {
|
247
|
+
:english_standard => {
|
248
|
+
:type => :standard,
|
249
|
+
:stopwords => "_english_"
|
267
250
|
}
|
268
251
|
}
|
269
252
|
}
|
270
|
-
|
271
|
-
|
253
|
+
}
|
254
|
+
)
|
255
|
+
wait_for_index(@name)
|
272
256
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
end
|
277
|
-
else
|
278
|
-
it "analyzes text and returns tokens" do
|
279
|
-
tokens = @index.analyze "Just a few words to analyze.", :index => nil
|
280
|
-
tokens = tokens["tokens"].map { |h| h["token"] }
|
281
|
-
assert_equal %w[just few words analyze], tokens
|
282
|
-
|
283
|
-
tokens = @index.analyze "Just a few words to analyze.", :analyzer => "simple", :index => nil
|
284
|
-
tokens = tokens["tokens"].map { |h| h["token"] }
|
285
|
-
assert_equal %w[just a few words to analyze], tokens
|
286
|
-
end
|
257
|
+
tokens = @index.analyze "Just a few words to analyze.", :analyzer => "english_standard"
|
258
|
+
tokens = tokens["tokens"].map { |h| h["token"] }
|
259
|
+
assert_equal %w[just few words analyze], tokens
|
287
260
|
end
|
288
261
|
|
289
262
|
describe "when an index exists" do
|
290
263
|
before do
|
264
|
+
suggest = {
|
265
|
+
:type => "completion",
|
266
|
+
:index_analyzer => "simple",
|
267
|
+
:search_analyzer => "simple",
|
268
|
+
:payloads => false
|
269
|
+
}
|
270
|
+
|
271
|
+
if es_version_2_x?
|
272
|
+
suggest[:analyzer] = suggest.delete(:index_analyzer)
|
273
|
+
end
|
274
|
+
|
291
275
|
@index.create(
|
292
276
|
:settings => { :number_of_shards => 1, :number_of_replicas => 0 },
|
293
277
|
:mappings => {
|
@@ -297,12 +281,7 @@ describe Elastomer::Client::Index do
|
|
297
281
|
:properties => {
|
298
282
|
:title => { :type => "string", :analyzer => "standard" },
|
299
283
|
:author => { :type => "string", :index => "not_analyzed" },
|
300
|
-
:suggest =>
|
301
|
-
:type => "completion",
|
302
|
-
:index_analyzer => "simple",
|
303
|
-
:search_analyzer => "simple",
|
304
|
-
:payloads => false
|
305
|
-
}
|
284
|
+
:suggest => suggest
|
306
285
|
}
|
307
286
|
}
|
308
287
|
}
|
@@ -349,11 +328,9 @@ describe Elastomer::Client::Index do
|
|
349
328
|
end
|
350
329
|
end
|
351
330
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
assert_includes response, "elastomer-index-test"
|
356
|
-
end
|
331
|
+
it "recovery" do
|
332
|
+
response = @index.recovery
|
333
|
+
assert_includes response, "elastomer-index-test"
|
357
334
|
end
|
358
335
|
|
359
336
|
it "clears caches" do
|
@@ -370,9 +347,12 @@ describe Elastomer::Client::Index do
|
|
370
347
|
end
|
371
348
|
end
|
372
349
|
|
373
|
-
|
374
|
-
|
375
|
-
|
350
|
+
# The /<index>/_status endpoint has been removed in ES 2.X
|
351
|
+
if es_version_1_x?
|
352
|
+
it "gets status" do
|
353
|
+
response = @index.status
|
354
|
+
assert_includes response["indices"], "elastomer-index-test"
|
355
|
+
end
|
376
356
|
end
|
377
357
|
|
378
358
|
it "gets segments" do
|
@@ -40,7 +40,7 @@ describe Elastomer::Client::MultiSearch do
|
|
40
40
|
populate!
|
41
41
|
|
42
42
|
body = [
|
43
|
-
'{"index" : "elastomer-msearch-test", "
|
43
|
+
'{"index" : "elastomer-msearch-test", "size" : 0}',
|
44
44
|
'{"query" : {"match_all" : {}}}',
|
45
45
|
'{"index" : "elastomer-msearch-test", "type": "doc2"}',
|
46
46
|
'{"query" : {"match": {"author" : "grantr"}}}',
|
@@ -69,7 +69,7 @@ describe Elastomer::Client::MultiSearch do
|
|
69
69
|
populate!
|
70
70
|
|
71
71
|
body = [
|
72
|
-
'{"index" : "elastomer-msearch-test", "
|
72
|
+
'{"index" : "elastomer-msearch-test", "size" : 0}',
|
73
73
|
'{"query" : {"match_all" : {}}}',
|
74
74
|
'{"index" : "elastomer-msearch-test", "type": "doc2"}',
|
75
75
|
'{"query" : {"match": {"author" : "grantr"}}}',
|
@@ -98,7 +98,7 @@ describe Elastomer::Client::MultiSearch do
|
|
98
98
|
populate!
|
99
99
|
|
100
100
|
h = $client.multi_search do |m|
|
101
|
-
m.search({:query => { :match_all => {}}}, :index => @name, :
|
101
|
+
m.search({:query => { :match_all => {}}}, :index => @name, :size => 0)
|
102
102
|
m.search({:query => { :match => { "title" => "author" }}}, :index => @name, :type => "doc2")
|
103
103
|
end
|
104
104
|
|
@@ -108,7 +108,7 @@ describe Elastomer::Client::MultiSearch do
|
|
108
108
|
assert_equal 2, response2["hits"]["total"]
|
109
109
|
|
110
110
|
h = @index.multi_search do |m|
|
111
|
-
m.search({:query => { :match_all => {}}}, :
|
111
|
+
m.search({:query => { :match_all => {}}}, :size => 0)
|
112
112
|
m.search({:query => { :match => { "title" => "author" }}}, :type => "doc2")
|
113
113
|
end
|
114
114
|
|
@@ -118,7 +118,7 @@ describe Elastomer::Client::MultiSearch do
|
|
118
118
|
assert_equal 2, response2["hits"]["total"]
|
119
119
|
|
120
120
|
h = @index.docs("doc1").multi_search do |m|
|
121
|
-
m.search({:query => { :match_all => {}}}, :
|
121
|
+
m.search({:query => { :match_all => {}}}, :size => 0)
|
122
122
|
m.search({:query => { :match => { "title" => "logging" }}}, :type => "doc2")
|
123
123
|
end
|
124
124
|
|
@@ -46,7 +46,7 @@ describe Elastomer::Client::Percolator do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "cannot delete all percolators by providing a nil id" do
|
49
|
-
assert_raises(ArgumentError) {
|
49
|
+
assert_raises(ArgumentError) { @index.percolator nil }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -100,7 +100,7 @@ describe Elastomer::Client::Repository do
|
|
100
100
|
response = repo.snapshot.get
|
101
101
|
assert_equal ["test-snapshot"], response["snapshots"].collect { |info| info["snapshot"] }
|
102
102
|
|
103
|
-
|
103
|
+
create_snapshot(repo, "test-snapshot2")
|
104
104
|
response = repo.snapshots.get
|
105
105
|
snapshot_names = response["snapshots"].collect { |info| info["snapshot"] }
|
106
106
|
assert_includes snapshot_names, "test-snapshot"
|
@@ -33,7 +33,15 @@ describe Elastomer::Client::Cluster do
|
|
33
33
|
template = @template.get
|
34
34
|
assert_equal [@name], template.keys
|
35
35
|
assert_equal "test-elastomer*", template[@name]["template"]
|
36
|
-
assert_equal "3", template[@name]["settings"]["index.number_of_shards"]
|
37
|
-
end
|
38
36
|
|
37
|
+
if es_version_1_x?
|
38
|
+
assert_equal "3", template[@name]["settings"]["index.number_of_shards"]
|
39
|
+
|
40
|
+
elsif es_version_2_x?
|
41
|
+
assert_equal "3", template[@name]["settings"]["index"]["number_of_shards"]
|
42
|
+
|
43
|
+
else
|
44
|
+
assert false, "Unsupported Elasticsearch version #{$client.semantic_version}"
|
45
|
+
end
|
46
|
+
end
|
39
47
|
end
|
data/test/client/warmer_test.rb
CHANGED
@@ -50,7 +50,7 @@ describe Elastomer::Client::Warmer do
|
|
50
50
|
assert_equal false, @index.warmer("test1").exists?
|
51
51
|
assert_equal false, @index.warmer("test1").exist?
|
52
52
|
|
53
|
-
|
53
|
+
@index.warmer("test1").create(:query => { :match_all => {}})
|
54
54
|
assert_equal true, @index.warmer("test1").exists?
|
55
55
|
end
|
56
56
|
end
|
data/test/client_test.rb
CHANGED
@@ -28,7 +28,13 @@ describe Elastomer::Client do
|
|
28
28
|
assert false, "exception was not raised when it should have been"
|
29
29
|
rescue Elastomer::Client::Error => err
|
30
30
|
assert_equal 404, err.status
|
31
|
-
|
31
|
+
if es_version_1_x?
|
32
|
+
assert_equal "IndexMissingException[[non-existent-index] missing]", err.message
|
33
|
+
elsif es_version_2_x?
|
34
|
+
assert_match %r/index_not_found_exception/, err.message
|
35
|
+
else
|
36
|
+
fail "Elasticserch #{$client.version} is not supported"
|
37
|
+
end
|
32
38
|
end
|
33
39
|
end
|
34
40
|
|
@@ -140,11 +146,12 @@ describe Elastomer::Client do
|
|
140
146
|
it "gets cluster info" do
|
141
147
|
h = $client.info
|
142
148
|
assert h.key?("name"), "expected cluster name to be returned"
|
143
|
-
assert h.key?("
|
149
|
+
assert h.key?("version"), "expected cluster version information to be returned"
|
150
|
+
assert h["version"].key?("number"), "expected cluster version number to be returned"
|
144
151
|
end
|
145
152
|
|
146
153
|
it "gets cluster version" do
|
147
|
-
assert_match
|
154
|
+
assert_match(/[\d\.]+/, $client.version)
|
148
155
|
end
|
149
156
|
|
150
157
|
it "gets semantic version" do
|
data/test/test_helper.rb
CHANGED
@@ -90,7 +90,18 @@ end
|
|
90
90
|
#
|
91
91
|
# Returns true if Elasticsearch version is 1.x.
|
92
92
|
def es_version_1_x?
|
93
|
-
$client.semantic_version >= "1.0.0"
|
93
|
+
$client.semantic_version >= "1.0.0" &&
|
94
|
+
$client.semantic_version < "2.0.0"
|
95
|
+
end
|
96
|
+
|
97
|
+
# Elasticsearch 2.0 changed some request formats in a non-backward-compatible
|
98
|
+
# way. Some tests need to know what version is running to structure requests
|
99
|
+
# as expected.
|
100
|
+
#
|
101
|
+
# Returns true if Elasticsearch version is 2.x.
|
102
|
+
def es_version_2_x?
|
103
|
+
$client.semantic_version >= "2.0.0" &&
|
104
|
+
$client.semantic_version < "3.0.0"
|
94
105
|
end
|
95
106
|
|
96
107
|
# Elasticsearch 1.4 changed the response body for interacting with index
|
@@ -135,7 +146,7 @@ def run_snapshot_tests?
|
|
135
146
|
begin
|
136
147
|
create_repo("elastomer-client-snapshot-test")
|
137
148
|
$run_snapshot_tests = true
|
138
|
-
rescue Elastomer::Client::Error
|
149
|
+
rescue Elastomer::Client::Error
|
139
150
|
puts "Could not create a snapshot repo. Snapshot tests will be disabled."
|
140
151
|
puts "To enable snapshot tests, add a path.repo setting to your elasticsearch.yml file."
|
141
152
|
$run_snapshot_tests = false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastomer-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Pease
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -267,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
267
|
version: '0'
|
268
268
|
requirements: []
|
269
269
|
rubyforge_project:
|
270
|
-
rubygems_version: 2.2.
|
270
|
+
rubygems_version: 2.2.3
|
271
271
|
signing_key:
|
272
272
|
specification_version: 4
|
273
273
|
summary: A library for interacting with Elasticsearch
|