elasticsearch-api 1.0.17 → 1.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -1
  3. data/elasticsearch-api.gemspec +6 -1
  4. data/lib/elasticsearch/api.rb +1 -0
  5. data/lib/elasticsearch/api/actions/bulk.rb +3 -1
  6. data/lib/elasticsearch/api/actions/cat/plugins.rb +1 -1
  7. data/lib/elasticsearch/api/actions/cat/tasks.rb +41 -0
  8. data/lib/elasticsearch/api/actions/cat/thread_pool.rb +3 -0
  9. data/lib/elasticsearch/api/actions/cluster/allocation_explain.rb +26 -0
  10. data/lib/elasticsearch/api/actions/cluster/get_settings.rb +4 -1
  11. data/lib/elasticsearch/api/actions/cluster/health.rb +4 -1
  12. data/lib/elasticsearch/api/actions/cluster/pending_tasks.rb +1 -1
  13. data/lib/elasticsearch/api/actions/cluster/reroute.rb +3 -1
  14. data/lib/elasticsearch/api/actions/cluster/stats.rb +30 -0
  15. data/lib/elasticsearch/api/actions/index.rb +1 -0
  16. data/lib/elasticsearch/api/actions/indices/analyze.rb +5 -0
  17. data/lib/elasticsearch/api/actions/indices/close.rb +2 -1
  18. data/lib/elasticsearch/api/actions/indices/create.rb +8 -1
  19. data/lib/elasticsearch/api/actions/indices/flush_synced.rb +5 -1
  20. data/lib/elasticsearch/api/actions/indices/get.rb +10 -1
  21. data/lib/elasticsearch/api/actions/indices/get_settings.rb +2 -0
  22. data/lib/elasticsearch/api/actions/indices/open.rb +2 -1
  23. data/lib/elasticsearch/api/actions/indices/put_mapping.rb +4 -1
  24. data/lib/elasticsearch/api/actions/indices/put_settings.rb +6 -0
  25. data/lib/elasticsearch/api/actions/indices/segments.rb +8 -6
  26. data/lib/elasticsearch/api/actions/ingest/delete_pipeline.rb +29 -0
  27. data/lib/elasticsearch/api/actions/ingest/get_pipeline.rb +27 -0
  28. data/lib/elasticsearch/api/actions/ingest/put_pipeline.rb +32 -0
  29. data/lib/elasticsearch/api/actions/ingest/simulate.rb +29 -0
  30. data/lib/elasticsearch/api/actions/nodes/hot_threads.rb +3 -1
  31. data/lib/elasticsearch/api/actions/nodes/info.rb +4 -2
  32. data/lib/elasticsearch/api/actions/nodes/stats.rb +3 -1
  33. data/lib/elasticsearch/api/actions/ping.rb +7 -1
  34. data/lib/elasticsearch/api/actions/reindex.rb +69 -0
  35. data/lib/elasticsearch/api/actions/search.rb +5 -0
  36. data/lib/elasticsearch/api/actions/tasks/list.rb +3 -0
  37. data/lib/elasticsearch/api/actions/update_by_query.rb +128 -0
  38. data/lib/elasticsearch/api/namespace/ingest.rb +20 -0
  39. data/lib/elasticsearch/api/utils.rb +55 -0
  40. data/lib/elasticsearch/api/version.rb +1 -1
  41. data/test/integration/yaml_test_runner.rb +3 -3
  42. data/test/unit/cat/plugins_test.rb +1 -1
  43. data/test/unit/cat/tasks_test.rb +26 -0
  44. data/test/unit/cluster/allocation_explain_test.rb +26 -0
  45. data/test/unit/cluster/health_test.rb +9 -0
  46. data/test/unit/cluster/pending_tasks_test.rb +1 -1
  47. data/test/unit/cluster/stats_test.rb +26 -0
  48. data/test/unit/ingest/delete_pipeline_test.rb +41 -0
  49. data/test/unit/ingest/get_pipeline_test.rb +41 -0
  50. data/test/unit/ingest/put_pipeline_test.rb +46 -0
  51. data/test/unit/ingest/simulate_test.rb +35 -0
  52. data/test/unit/ping_test.rb +6 -1
  53. data/test/unit/reindex_test.rb +26 -0
  54. data/test/unit/update_by_query_test.rb +26 -0
  55. data/test/unit/utils_test.rb +59 -0
  56. metadata +34 -6
@@ -0,0 +1,20 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Ingest
4
+ module Actions; end
5
+
6
+ # Client for the "ingest" namespace (includes the {Ingest::Actions} methods)
7
+ #
8
+ class IngestClient
9
+ include Common::Client, Common::Client::Base, Ingest::Actions
10
+ end
11
+
12
+ # Proxy method for {IngestClient}, available in the receiving object
13
+ #
14
+ def ingest
15
+ @ingest ||= IngestClient.new(self)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -203,6 +203,61 @@ module Elasticsearch
203
203
  end
204
204
  end
205
205
 
206
+ def __report_unsupported_parameters(arguments, params=[])
207
+ messages = []
208
+ unsupported_params = params.select {|d| d.is_a?(Hash) ? arguments.include?(d.keys.first) : arguments.include?(d) }
209
+
210
+ unsupported_params.each do |param|
211
+ name = case param
212
+ when Symbol
213
+ param
214
+ when Hash
215
+ param.keys.first
216
+ else
217
+ raise ArgumentError, "The param must be a Symbol or a Hash"
218
+ end
219
+
220
+ explanation = if param.is_a?(Hash)
221
+ ". #{param.values.first[:explanation]}."
222
+ else
223
+ ". This parameter is not supported in the version you're using: #{Elasticsearch::API::VERSION}, and will be removed in the next release."
224
+ end
225
+
226
+ message = "[!] You are using unsupported parameter [:#{name}]"
227
+
228
+ if source = caller && caller.last
229
+ message += " in `#{source}`"
230
+ end
231
+
232
+ message += explanation
233
+
234
+ messages << message
235
+ end
236
+
237
+ unless messages.empty?
238
+ if terminal = STDERR.tty?
239
+ STDERR.puts messages.map { |m| "\e[31;1m#{m}\e[0m" }.join("\n")
240
+ else
241
+ STDERR.puts messages.join("\n")
242
+ end
243
+ end
244
+ end
245
+
246
+ def __report_unsupported_method(name)
247
+ message = "[!] You are using unsupported method [#{name}]"
248
+ if source = caller && caller.last
249
+ message += " in `#{source}`"
250
+ end
251
+
252
+ message += ". This method is not supported in the version you're using: #{Elasticsearch::API::VERSION}, and will be removed in the next release."
253
+
254
+ if terminal = STDERR.tty?
255
+ STDERR.puts "\e[31;1m#{message}\e[0m"
256
+ else
257
+ STDERR.puts message
258
+ end
259
+ end
260
+
206
261
  extend self
207
262
  end
208
263
  end
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module API
3
- VERSION = "1.0.17"
3
+ VERSION = "1.0.18"
4
4
  end
5
5
  end
@@ -289,8 +289,8 @@ suites.each do |suite|
289
289
  # --- Register context setup -------------------------------------------
290
290
  #
291
291
  setup do
292
- $client.indices.delete index: '_all'
293
- $client.indices.delete_template name: '*'
292
+ $client.indices.delete index: '_all', ignore: 404
293
+ $client.indices.delete_template name: '*', ignore: 404
294
294
  $client.snapshot.delete repository: 'test_repo_create_1', snapshot: 'test_snapshot', ignore: 404
295
295
  $client.snapshot.delete repository: 'test_repo_restore_1', snapshot: 'test_snapshot', ignore: 404
296
296
  $client.snapshot.delete repository: 'test_cat_snapshots_1', snapshot: 'snap1', ignore: 404
@@ -313,7 +313,7 @@ suites.each do |suite|
313
313
  # --- Register context teardown ----------------------------------------
314
314
  #
315
315
  teardown do
316
- $client.indices.delete index: '_all'
316
+ $client.indices.delete index: '_all', ignore: 404
317
317
  end
318
318
 
319
319
  files = Dir[suite.join('*.{yml,yaml}')]
@@ -10,7 +10,7 @@ module Elasticsearch
10
10
  should "perform correct request" do
11
11
  subject.expects(:perform_request).with do |method, url, params, body|
12
12
  assert_equal 'GET', method
13
- assert_equal '/_cat/plugins', url
13
+ assert_equal '_cat/plugins', url
14
14
  assert_equal Hash.new, params
15
15
  assert_nil body
16
16
  true
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class CatTasksTest < ::Test::Unit::TestCase
6
+
7
+ context "Cat: Tasks" do
8
+ subject { FakeClient.new }
9
+
10
+ should "perform correct request" do
11
+ subject.expects(:perform_request).with do |method, url, params, body|
12
+ assert_equal 'GET', method
13
+ assert_equal '_cat/tasks', url
14
+ assert_equal Hash.new, params
15
+ assert_nil body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.cat.tasks
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class ClusterAllocationExplainTest < ::Test::Unit::TestCase
6
+
7
+ context "Cluster: Allocation explain" do
8
+ subject { FakeClient.new }
9
+
10
+ should "perform correct request" do
11
+ subject.expects(:perform_request).with do |method, url, params, body|
12
+ assert_equal 'GET', method
13
+ assert_equal '_cluster/allocation/explain', url
14
+ assert_equal Hash.new, params
15
+ assert_equal nil, body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.cluster.allocation_explain
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -31,6 +31,15 @@ module Elasticsearch
31
31
  subject.cluster.health :level => 'indices'
32
32
  end
33
33
 
34
+ should "return health for a specific index" do
35
+ subject.expects(:perform_request).with do |method, url, params, body|
36
+ assert_equal '_cluster/health/foo', url
37
+ true
38
+ end.returns(FakeResponse.new)
39
+
40
+ subject.cluster.health :index => 'foo'
41
+ end
42
+
34
43
  end
35
44
 
36
45
  end
@@ -10,7 +10,7 @@ module Elasticsearch
10
10
  should "perform correct request" do
11
11
  subject.expects(:perform_request).with do |method, url, params, body|
12
12
  assert_equal 'GET', method
13
- assert_equal '/_cluster/pending_tasks', url
13
+ assert_equal '_cluster/pending_tasks', url
14
14
  assert_equal Hash.new, params
15
15
  assert_nil body
16
16
  true
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class ClusterStatsTest < ::Test::Unit::TestCase
6
+
7
+ context "Cluster: Stats" do
8
+ subject { FakeClient.new }
9
+
10
+ should "perform correct request" do
11
+ subject.expects(:perform_request).with do |method, url, params, body|
12
+ assert_equal 'GET', method
13
+ assert_equal '_cluster/stats', url
14
+ assert_equal Hash.new, params
15
+ assert_nil body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.cluster.stats
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class IngestDeletePipelineTest < ::Test::Unit::TestCase
6
+
7
+ context "Ingest: Delete pipeline" do
8
+ subject { FakeClient.new }
9
+
10
+ should "require the :id argument" do
11
+ assert_raise ArgumentError do
12
+ subject.ingest.delete_pipeline
13
+ end
14
+ end
15
+
16
+ should "perform correct request" do
17
+ subject.expects(:perform_request).with do |method, url, params, body|
18
+ assert_equal 'DELETE', method
19
+ assert_equal '_ingest/pipeline/foo', url
20
+ assert_equal Hash.new, params
21
+ assert_nil body
22
+ true
23
+ end.returns(FakeResponse.new)
24
+
25
+ subject.ingest.delete_pipeline :id => 'foo'
26
+ end
27
+
28
+ should "URL-escape the ID" do
29
+ subject.expects(:perform_request).with do |method, url, params, body|
30
+ assert_equal '_ingest/pipeline/foo%5Ebar', url
31
+ true
32
+ end.returns(FakeResponse.new)
33
+
34
+ subject.ingest.delete_pipeline :id => 'foo^bar'
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class IngestGetPipelineTest < ::Test::Unit::TestCase
6
+
7
+ context "Ingest: Get pipeline" do
8
+ subject { FakeClient.new }
9
+
10
+ should "require the :id argument" do
11
+ assert_raise ArgumentError do
12
+ subject.ingest.get_pipeline
13
+ end
14
+ end
15
+
16
+ should "perform correct request" do
17
+ subject.expects(:perform_request).with do |method, url, params, body|
18
+ assert_equal 'GET', method
19
+ assert_equal '_ingest/pipeline/foo', url
20
+ assert_equal Hash.new, params
21
+ assert_nil body
22
+ true
23
+ end.returns(FakeResponse.new)
24
+
25
+ subject.ingest.get_pipeline :id => 'foo'
26
+ end
27
+
28
+ should "URL-escape the ID" do
29
+ subject.expects(:perform_request).with do |method, url, params, body|
30
+ assert_equal '_ingest/pipeline/foo%5Ebar', url
31
+ true
32
+ end.returns(FakeResponse.new)
33
+
34
+ subject.ingest.get_pipeline :id => 'foo^bar'
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class IngestPutPipelineTest < ::Test::Unit::TestCase
6
+
7
+ context "Ingest: Put pipeline" do
8
+ subject { FakeClient.new }
9
+
10
+ should "require the :id argument" do
11
+ assert_raise ArgumentError do
12
+ subject.ingest.put_pipeline :body => {}
13
+ end
14
+ end
15
+
16
+ should "require the :body argument" do
17
+ assert_raise ArgumentError do
18
+ subject.ingest.put_pipeline :id => 'foo'
19
+ end
20
+ end
21
+
22
+ should "perform correct request" do
23
+ subject.expects(:perform_request).with do |method, url, params, body|
24
+ assert_equal 'PUT', method
25
+ assert_equal '_ingest/pipeline/foo', url
26
+ assert_equal Hash.new, params
27
+ assert_equal Hash.new, body
28
+ true
29
+ end.returns(FakeResponse.new)
30
+
31
+ subject.ingest.put_pipeline :id => 'foo', :body => {}
32
+ end
33
+
34
+ should "URL-escape the ID" do
35
+ subject.expects(:perform_request).with do |method, url, params, body|
36
+ assert_equal '_ingest/pipeline/foo%5Ebar', url
37
+ true
38
+ end.returns(FakeResponse.new)
39
+
40
+ subject.ingest.put_pipeline :id => 'foo^bar', :body => {}
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class IngestSimulateTest < ::Test::Unit::TestCase
6
+
7
+ context "Ingest: Simulate" do
8
+ subject { FakeClient.new }
9
+
10
+ should "perform correct request" do
11
+ subject.expects(:perform_request).with do |method, url, params, body|
12
+ assert_equal 'GET', method
13
+ assert_equal '_ingest/pipeline/_simulate', url
14
+ assert_equal Hash.new, params
15
+ assert_equal Hash.new, body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.ingest.simulate :body => {}
20
+ end
21
+
22
+ should "perform correct request with a pipeline ID" do
23
+ subject.expects(:perform_request).with do |method, url, params, body|
24
+ assert_equal '_ingest/pipeline/foo/_simulate', url
25
+ true
26
+ end.returns(FakeResponse.new)
27
+
28
+ subject.ingest.simulate :id => 'foo', :body => {}
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -4,7 +4,7 @@ module Elasticsearch
4
4
  module Test
5
5
  class PingTest < ::Test::Unit::TestCase
6
6
 
7
- context "Indices: Exists" do
7
+ context "Ping" do
8
8
  subject { FakeClient.new }
9
9
 
10
10
  should "perform correct request" do
@@ -34,6 +34,11 @@ module Elasticsearch
34
34
  assert_equal false, subject.ping
35
35
  end
36
36
 
37
+ should "return false on 'connection failed' exceptions" do
38
+ subject.expects(:perform_request).raises(StandardError.new 'ConnectionFailed')
39
+ assert_equal false, subject.ping
40
+ end
41
+
37
42
  should "re-raise generic exceptions" do
38
43
  subject.expects(:perform_request).raises(StandardError)
39
44
  assert_raise(StandardError) do
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class ReindexTest < ::Test::Unit::TestCase
6
+
7
+ context "Reindex" do
8
+ subject { FakeClient.new }
9
+
10
+ should "perform correct request" do
11
+ subject.expects(:perform_request).with do |method, url, params, body|
12
+ assert_equal 'POST', method
13
+ assert_equal '_reindex', url
14
+ assert_equal Hash.new, params
15
+ assert_equal Hash.new, body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.reindex :body => {}
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
26
+ end