elasticsearch-api 1.0.6 → 1.0.7

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.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -0
  3. data/Rakefile +3 -3
  4. data/elasticsearch-api.gemspec +4 -1
  5. data/lib/elasticsearch/api.rb +19 -0
  6. data/lib/elasticsearch/api/actions/abort_benchmark.rb +1 -1
  7. data/lib/elasticsearch/api/actions/benchmark.rb +1 -1
  8. data/lib/elasticsearch/api/actions/bulk.rb +1 -1
  9. data/lib/elasticsearch/api/actions/cat/aliases.rb +1 -1
  10. data/lib/elasticsearch/api/actions/cat/allocation.rb +1 -1
  11. data/lib/elasticsearch/api/actions/cat/count.rb +1 -1
  12. data/lib/elasticsearch/api/actions/cat/fielddata.rb +1 -1
  13. data/lib/elasticsearch/api/actions/cat/health.rb +1 -1
  14. data/lib/elasticsearch/api/actions/cat/help.rb +1 -1
  15. data/lib/elasticsearch/api/actions/cat/indices.rb +1 -1
  16. data/lib/elasticsearch/api/actions/cat/master.rb +1 -1
  17. data/lib/elasticsearch/api/actions/cat/nodes.rb +1 -1
  18. data/lib/elasticsearch/api/actions/cat/pending_tasks.rb +1 -1
  19. data/lib/elasticsearch/api/actions/cat/recovery.rb +1 -1
  20. data/lib/elasticsearch/api/actions/cat/segments.rb +34 -0
  21. data/lib/elasticsearch/api/actions/cat/shards.rb +1 -1
  22. data/lib/elasticsearch/api/actions/cat/thread_pool.rb +1 -1
  23. data/lib/elasticsearch/api/actions/clear_scroll.rb +12 -3
  24. data/lib/elasticsearch/api/actions/cluster/get_settings.rb +1 -1
  25. data/lib/elasticsearch/api/actions/cluster/health.rb +1 -1
  26. data/lib/elasticsearch/api/actions/cluster/pending_tasks.rb +1 -1
  27. data/lib/elasticsearch/api/actions/cluster/put_settings.rb +1 -1
  28. data/lib/elasticsearch/api/actions/cluster/reroute.rb +1 -1
  29. data/lib/elasticsearch/api/actions/cluster/state.rb +8 -2
  30. data/lib/elasticsearch/api/actions/count.rb +1 -1
  31. data/lib/elasticsearch/api/actions/count_percolate.rb +1 -1
  32. data/lib/elasticsearch/api/actions/delete.rb +1 -1
  33. data/lib/elasticsearch/api/actions/delete_by_query.rb +1 -1
  34. data/lib/elasticsearch/api/actions/delete_script.rb +1 -1
  35. data/lib/elasticsearch/api/actions/delete_template.rb +1 -1
  36. data/lib/elasticsearch/api/actions/exists.rb +4 -2
  37. data/lib/elasticsearch/api/actions/explain.rb +1 -1
  38. data/lib/elasticsearch/api/actions/get.rb +2 -2
  39. data/lib/elasticsearch/api/actions/get_script.rb +1 -1
  40. data/lib/elasticsearch/api/actions/get_source.rb +2 -2
  41. data/lib/elasticsearch/api/actions/get_template.rb +1 -1
  42. data/lib/elasticsearch/api/actions/index.rb +1 -1
  43. data/lib/elasticsearch/api/actions/indices/analyze.rb +5 -3
  44. data/lib/elasticsearch/api/actions/indices/clear_cache.rb +1 -1
  45. data/lib/elasticsearch/api/actions/indices/close.rb +1 -1
  46. data/lib/elasticsearch/api/actions/indices/create.rb +1 -1
  47. data/lib/elasticsearch/api/actions/indices/delete.rb +7 -1
  48. data/lib/elasticsearch/api/actions/indices/delete_alias.rb +1 -1
  49. data/lib/elasticsearch/api/actions/indices/delete_mapping.rb +1 -1
  50. data/lib/elasticsearch/api/actions/indices/delete_template.rb +1 -1
  51. data/lib/elasticsearch/api/actions/indices/delete_warmer.rb +1 -1
  52. data/lib/elasticsearch/api/actions/indices/exists.rb +3 -1
  53. data/lib/elasticsearch/api/actions/indices/exists_alias.rb +3 -1
  54. data/lib/elasticsearch/api/actions/indices/exists_template.rb +3 -2
  55. data/lib/elasticsearch/api/actions/indices/exists_type.rb +3 -1
  56. data/lib/elasticsearch/api/actions/indices/flush.rb +1 -1
  57. data/lib/elasticsearch/api/actions/indices/get.rb +1 -1
  58. data/lib/elasticsearch/api/actions/indices/get_alias.rb +1 -1
  59. data/lib/elasticsearch/api/actions/indices/get_aliases.rb +1 -1
  60. data/lib/elasticsearch/api/actions/indices/get_field_mapping.rb +1 -1
  61. data/lib/elasticsearch/api/actions/indices/get_mapping.rb +1 -1
  62. data/lib/elasticsearch/api/actions/indices/get_settings.rb +1 -1
  63. data/lib/elasticsearch/api/actions/indices/get_template.rb +3 -2
  64. data/lib/elasticsearch/api/actions/indices/get_warmer.rb +1 -1
  65. data/lib/elasticsearch/api/actions/indices/open.rb +1 -1
  66. data/lib/elasticsearch/api/actions/indices/optimize.rb +1 -1
  67. data/lib/elasticsearch/api/actions/indices/put_alias.rb +2 -2
  68. data/lib/elasticsearch/api/actions/indices/put_mapping.rb +1 -1
  69. data/lib/elasticsearch/api/actions/indices/put_settings.rb +1 -1
  70. data/lib/elasticsearch/api/actions/indices/put_template.rb +1 -1
  71. data/lib/elasticsearch/api/actions/indices/put_warmer.rb +1 -1
  72. data/lib/elasticsearch/api/actions/indices/recovery.rb +1 -1
  73. data/lib/elasticsearch/api/actions/indices/refresh.rb +1 -1
  74. data/lib/elasticsearch/api/actions/indices/segments.rb +1 -1
  75. data/lib/elasticsearch/api/actions/indices/snapshot_index.rb +1 -1
  76. data/lib/elasticsearch/api/actions/indices/stats.rb +1 -1
  77. data/lib/elasticsearch/api/actions/indices/status.rb +1 -1
  78. data/lib/elasticsearch/api/actions/indices/update_aliases.rb +1 -1
  79. data/lib/elasticsearch/api/actions/indices/upgrade.rb +1 -1
  80. data/lib/elasticsearch/api/actions/indices/validate_query.rb +1 -1
  81. data/lib/elasticsearch/api/actions/info.rb +1 -1
  82. data/lib/elasticsearch/api/actions/list_benchmarks.rb +1 -1
  83. data/lib/elasticsearch/api/actions/mget.rb +1 -1
  84. data/lib/elasticsearch/api/actions/mlt.rb +1 -1
  85. data/lib/elasticsearch/api/actions/mpercolate.rb +1 -1
  86. data/lib/elasticsearch/api/actions/msearch.rb +1 -1
  87. data/lib/elasticsearch/api/actions/mtermvectors.rb +1 -1
  88. data/lib/elasticsearch/api/actions/nodes/hot_threads.rb +1 -1
  89. data/lib/elasticsearch/api/actions/nodes/info.rb +18 -2
  90. data/lib/elasticsearch/api/actions/nodes/shutdown.rb +1 -1
  91. data/lib/elasticsearch/api/actions/nodes/stats.rb +1 -1
  92. data/lib/elasticsearch/api/actions/percolate.rb +4 -5
  93. data/lib/elasticsearch/api/actions/ping.rb +1 -1
  94. data/lib/elasticsearch/api/actions/put_script.rb +1 -1
  95. data/lib/elasticsearch/api/actions/put_template.rb +1 -1
  96. data/lib/elasticsearch/api/actions/scroll.rb +2 -2
  97. data/lib/elasticsearch/api/actions/search.rb +4 -3
  98. data/lib/elasticsearch/api/actions/search_shards.rb +1 -1
  99. data/lib/elasticsearch/api/actions/search_template.rb +1 -1
  100. data/lib/elasticsearch/api/actions/snapshot/create.rb +1 -1
  101. data/lib/elasticsearch/api/actions/snapshot/create_repository.rb +1 -1
  102. data/lib/elasticsearch/api/actions/snapshot/delete.rb +1 -1
  103. data/lib/elasticsearch/api/actions/snapshot/delete_repository.rb +1 -1
  104. data/lib/elasticsearch/api/actions/snapshot/get.rb +1 -1
  105. data/lib/elasticsearch/api/actions/snapshot/get_repository.rb +1 -1
  106. data/lib/elasticsearch/api/actions/snapshot/restore.rb +1 -1
  107. data/lib/elasticsearch/api/actions/snapshot/status.rb +1 -1
  108. data/lib/elasticsearch/api/actions/snapshot/verify_repository.rb +1 -1
  109. data/lib/elasticsearch/api/actions/suggest.rb +1 -1
  110. data/lib/elasticsearch/api/actions/{termvector.rb → termvectors.rb} +24 -7
  111. data/lib/elasticsearch/api/actions/update.rb +1 -1
  112. data/lib/elasticsearch/api/utils.rb +27 -6
  113. data/lib/elasticsearch/api/version.rb +1 -1
  114. data/test/integration/yaml_test_runner.rb +3 -2
  115. data/test/unit/api_test.rb +24 -0
  116. data/test/unit/cat/segments_test.rb +26 -0
  117. data/test/unit/clear_scroll_test.rb +4 -4
  118. data/test/unit/exists_document_test.rb +5 -0
  119. data/test/unit/indices/delete_test.rb +7 -0
  120. data/test/unit/indices/exists_alias_test.rb +5 -0
  121. data/test/unit/indices/exists_test.rb +5 -0
  122. data/test/unit/indices/exists_type_test.rb +5 -0
  123. data/test/unit/indices/put_alias_test.rb +9 -0
  124. data/test/unit/nodes/info_test.rb +9 -0
  125. data/test/unit/scroll_test.rb +1 -2
  126. data/test/unit/{termvector_test.rb → termvectors_test.rb} +15 -12
  127. data/test/unit/utils_test.rb +22 -0
  128. data/utils/Gemfile +9 -0
  129. data/utils/Thorfile +3 -0
  130. data/utils/thor/generate_api.rb +189 -0
  131. data/utils/thor/generate_source.rb +122 -0
  132. data/utils/thor/lister.rb +41 -0
  133. data/utils/thor/templates/ruby/method.erb +62 -0
  134. data/utils/thor/templates/ruby/test.erb +26 -0
  135. data/utils/thor/templates/ruby/test_helper.rb +71 -0
  136. metadata +18 -5
@@ -39,7 +39,7 @@ module Elasticsearch
39
39
  repository = arguments.delete(:repository)
40
40
  snapshot = arguments.delete(:snapshot)
41
41
 
42
- method = 'POST'
42
+ method = HTTP_POST
43
43
  path = Utils.__pathify( '_snapshot', Utils.__escape(repository), Utils.__escape(snapshot), '_restore' )
44
44
 
45
45
  params = Utils.__validate_and_extract_params arguments, valid_params
@@ -26,7 +26,7 @@ module Elasticsearch
26
26
  repository = arguments.delete(:repository)
27
27
  snapshot = arguments.delete(:snapshot)
28
28
 
29
- method = 'GET'
29
+ method = HTTP_GET
30
30
 
31
31
  path = Utils.__pathify( '_snapshot', Utils.__escape(repository), Utils.__escape(snapshot), '_status')
32
32
  params = Utils.__validate_and_extract_params arguments, valid_params
@@ -20,7 +20,7 @@ module Elasticsearch
20
20
  :timeout ]
21
21
 
22
22
  repository = arguments.delete(:repository)
23
- method = 'POST'
23
+ method = HTTP_POST
24
24
  path = Utils.__pathify( '_snapshot', Utils.__escape(repository), '_verify' )
25
25
  params = Utils.__validate_and_extract_params arguments, valid_params
26
26
  body = nil
@@ -33,7 +33,7 @@ module Elasticsearch
33
33
  :routing,
34
34
  :source ]
35
35
 
36
- method = 'POST'
36
+ method = HTTP_POST
37
37
  path = Utils.__pathify( Utils.__listify(arguments[:index]), '_suggest' )
38
38
 
39
39
  params = Utils.__validate_and_extract_params arguments, valid_params
@@ -4,7 +4,7 @@ module Elasticsearch
4
4
 
5
5
  # Return information and statistics about terms in the fields of a particular document
6
6
  #
7
- # @example Get statistics for a specific document
7
+ # @example Get statistics for an indexed document
8
8
  #
9
9
  # client.indices.create index: 'my_index',
10
10
  # body: {
@@ -22,12 +22,23 @@ module Elasticsearch
22
22
  #
23
23
  # client.index index: 'my_index', type: 'my_type', id: '1', body: { text: 'Foo Bar Fox' }
24
24
  #
25
- # client.termvector index: 'my_index', type: 'my_type', id: '1'
25
+ # client.termvectors index: 'my_index', type: 'my_type', id: '1'
26
+ # # => { ..., "term_vectors" => { "text" => { "field_statistics" => { ... }, "terms" => { "bar" => ... } } }
27
+ #
28
+ #
29
+ # @example Get statistics for an arbitrary document
30
+ #
31
+ # client.termvector index: 'my_index', type: 'my_type',
32
+ # body: {
33
+ # doc: {
34
+ # text: 'Foo Bar Fox'
35
+ # }
36
+ # }
26
37
  # # => { ..., "term_vectors" => { "text" => { "field_statistics" => { ... }, "terms" => { "bar" => ... } } }
27
38
  #
28
39
  # @option arguments [String] :index The name of the index (*Required*)
29
40
  # @option arguments [String] :type The type of the document (*Required*)
30
- # @option arguments [String] :id The document ID (*Required*)
41
+ # @option arguments [String] :id The document ID
31
42
  # @option arguments [Hash] :body The request definition
32
43
  # @option arguments [Boolean] :term_statistics Whether total term frequency and
33
44
  # document frequency should be returned
@@ -46,10 +57,9 @@ module Elasticsearch
46
57
  #
47
58
  # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/docs-termvectors.html
48
59
  #
49
- def termvector(arguments={})
60
+ def termvectors(arguments={})
50
61
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
51
62
  raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
52
- raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
53
63
 
54
64
  valid_params = [
55
65
  :term_statistics,
@@ -63,18 +73,25 @@ module Elasticsearch
63
73
  :routing,
64
74
  :parent ]
65
75
 
66
- method = 'GET'
76
+ method = HTTP_GET
77
+ endpoint = arguments.delete(:endpoint) || '_termvectors'
67
78
 
68
79
  path = Utils.__pathify Utils.__escape(arguments[:index]),
69
80
  Utils.__escape(arguments[:type]),
70
81
  arguments[:id],
71
- '_termvector'
82
+ endpoint
72
83
 
73
84
  params = Utils.__validate_and_extract_params arguments, valid_params
74
85
  body = arguments[:body]
75
86
 
76
87
  perform_request(method, path, params, body).body
77
88
  end
89
+
90
+ # @deprecated Use the plural version, {#termvectors}
91
+ #
92
+ def termvector(arguments={})
93
+ termvectors(arguments.merge :endpoint => '_termvector')
94
+ end
78
95
  end
79
96
  end
80
97
  end
@@ -83,7 +83,7 @@ module Elasticsearch
83
83
  :version,
84
84
  :version_type ]
85
85
 
86
- method = 'POST'
86
+ method = HTTP_POST
87
87
  path = Utils.__pathify Utils.__escape(arguments[:index]),
88
88
  Utils.__escape(arguments[:type]),
89
89
  Utils.__escape(arguments[:id]),
@@ -110,24 +110,45 @@ module Elasticsearch
110
110
  # @raise [ArgumentError] If the arguments Hash contains invalid keys
111
111
  #
112
112
  # @example Extract parameters
113
- # __validate_and_extract_params { :foo => 'qux' }, [:foo, :bar]
113
+ # __validate_and_extract_params( { :foo => 'qux' }, [:foo, :bar] )
114
114
  # # => { :foo => 'qux' }
115
115
  #
116
116
  # @example Raise an exception for invalid parameters
117
- # __validate_and_extract_params { :foo => 'qux', :bam => 'mux' }, [:foo, :bar]
117
+ # __validate_and_extract_params( { :foo => 'qux', :bam => 'mux' }, [:foo, :bar] )
118
118
  # # ArgumentError: "URL parameter 'bam' is not supported"
119
119
  #
120
+ # @example Skip validating parameters
121
+ # __validate_and_extract_params( { :foo => 'q', :bam => 'm' }, [:foo, :bar], { skip_parameter_validation: true } )
122
+ # # => { :foo => "q", :bam => "m" }
123
+ #
124
+ # @example Skip validating parameters when the module setting is set
125
+ # Elasticsearch::API.settings[:skip_parameter_validation] = true
126
+ # __validate_and_extract_params( { :foo => 'q', :bam => 'm' }, [:foo, :bar] )
127
+ # # => { :foo => "q", :bam => "m" }
128
+ #
120
129
  # @api private
121
130
  #
122
- def __validate_and_extract_params(arguments, valid_params=[])
131
+ def __validate_and_extract_params(arguments, params=[], options={})
132
+ if options[:skip_parameter_validation] || Elasticsearch::API.settings[:skip_parameter_validation]
133
+ arguments
134
+ else
135
+ __validate_params(arguments, params)
136
+ __extract_params(arguments, params)
137
+ end
138
+ end
139
+
140
+ def __validate_params(arguments, valid_params=[])
123
141
  arguments.each do |k,v|
124
142
  raise ArgumentError, "URL parameter '#{k}' is not supported" \
125
143
  unless COMMON_PARAMS.include?(k) || COMMON_QUERY_PARAMS.include?(k) || valid_params.include?(k)
126
144
  end
145
+ end
127
146
 
128
- params = arguments.select { |k,v| COMMON_QUERY_PARAMS.include?(k) || valid_params.include?(k) }
129
- params = Hash[params] unless params.is_a?(Hash) # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
130
- params
147
+ def __extract_params(arguments, params=[])
148
+ result = arguments.select { |k,v| COMMON_QUERY_PARAMS.include?(k) || params.include?(k) }
149
+ result = Hash[result] unless result.is_a?(Hash) # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
150
+ result = Hash[result.map { |k,v| v.is_a?(Array) ? [k, __listify(v)] : [k,v] }] # Listify Arrays
151
+ result
131
152
  end
132
153
 
133
154
  # Extracts the valid parts of the URL from the arguments
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module API
3
- VERSION = "1.0.6"
3
+ VERSION = "1.0.7"
4
4
  end
5
5
  end
@@ -14,7 +14,8 @@ require 'elasticsearch/extensions/test/startup_shutdown'
14
14
  require 'elasticsearch/extensions/test/profiling' unless JRUBY
15
15
 
16
16
  # Skip features
17
- SKIP_FEATURES = ENV['TEST_SKIP_FEATURES'] || ''
17
+ skip_features = 'stash_in_path,requires_replica'
18
+ SKIP_FEATURES = ENV.fetch('TEST_SKIP_FEATURES', skip_features)
18
19
 
19
20
  # Turn configuration
20
21
  ENV['ansi'] = 'false' if ENV['CI']
@@ -261,7 +262,7 @@ end
261
262
  include Elasticsearch::YamlTestSuite
262
263
 
263
264
  PATH = Pathname(ENV['TEST_REST_API_SPEC'] || \
264
- File.expand_path('../../../../support/elasticsearch/rest-api-spec/test', __FILE__))
265
+ File.expand_path('../../../../tmp/elasticsearch/rest-api-spec/test', __FILE__))
265
266
  suites = Dir.glob(PATH.join('*')).map { |d| Pathname(d) }
266
267
  suites = suites.select { |s| s.to_s =~ Regexp.new(ENV['FILTER']) } if ENV['FILTER']
267
268
 
@@ -0,0 +1,24 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'test_helper'
4
+
5
+ module Elasticsearch
6
+ module Test
7
+ class APITest < ::Test::Unit::TestCase
8
+
9
+ context "The API module" do
10
+
11
+ should "access the settings" do
12
+ assert_not_nil Elasticsearch::API.settings
13
+ end
14
+
15
+ should "allow to set settings" do
16
+ assert_nothing_raised { Elasticsearch::API.settings[:foo] = 'bar' }
17
+ assert_equal 'bar', Elasticsearch::API.settings[:foo]
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class CatSegmentsTest < ::Test::Unit::TestCase
6
+
7
+ context "Cat: Segments" 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/segments', url
14
+ assert_equal Hash.new, params
15
+ assert_nil body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.cat.segments
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -10,9 +10,9 @@ 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 'DELETE', method
13
- assert_equal '_search/scroll/abc123', url
13
+ assert_equal '_search/scroll', url
14
14
  assert_equal Hash.new, params
15
- assert_nil body
15
+ assert_equal 'abc123', body
16
16
  true
17
17
  end.returns(FakeResponse.new)
18
18
 
@@ -22,9 +22,9 @@ module Elasticsearch
22
22
  should "listify scroll IDs" do
23
23
  subject.expects(:perform_request).with do |method, url, params, body|
24
24
  assert_equal 'DELETE', method
25
- assert_equal '_search/scroll/abc123,def456', url
25
+ assert_equal '_search/scroll', url
26
26
  assert_equal Hash.new, params
27
- assert_nil body
27
+ assert_equal 'abc123,def456', body
28
28
  true
29
29
  end.returns(FakeResponse.new)
30
30
 
@@ -78,6 +78,11 @@ module Elasticsearch
78
78
  end
79
79
  end
80
80
 
81
+ should "be aliased as predicate method" do
82
+ assert_nothing_raised do
83
+ subject.exists?(:index => 'foo', :type => 'bar', :id => '1') == subject.exists(:index => 'foo', :type => 'bar', :id => '1')
84
+ end
85
+ end
81
86
  end
82
87
 
83
88
  end
@@ -47,6 +47,13 @@ module Elasticsearch
47
47
  subject.indices.delete :index => 'foo^bar'
48
48
  end
49
49
 
50
+ should "catch a NotFound exception with the ignore parameter" do
51
+ subject.expects(:perform_request).raises(NotFound)
52
+
53
+ assert_nothing_raised do
54
+ subject.indices.delete :index => 'foo', :ignore => 404
55
+ end
56
+ end
50
57
  end
51
58
 
52
59
  end
@@ -61,6 +61,11 @@ module Elasticsearch
61
61
  end
62
62
  end
63
63
 
64
+ should "be aliased as predicate method" do
65
+ assert_nothing_raised do
66
+ subject.indices.exists_alias?(:name => 'foo') == subject.indices.exists_alias(:name => 'foo')
67
+ end
68
+ end
64
69
  end
65
70
 
66
71
  end
@@ -59,6 +59,11 @@ module Elasticsearch
59
59
  end
60
60
  end
61
61
 
62
+ should "be aliased as predicate method" do
63
+ assert_nothing_raised do
64
+ subject.indices.exists?(:index => 'foo') == subject.indices.exists(:index => 'foo')
65
+ end
66
+ end
62
67
  end
63
68
 
64
69
  end
@@ -61,6 +61,11 @@ module Elasticsearch
61
61
  end
62
62
  end
63
63
 
64
+ should "be aliased as predicate method" do
65
+ assert_nothing_raised do
66
+ subject.indices.exists_type?(:index => 'foo', :type => 'bar') == subject.indices.exists_type(:index => 'foo', :type => 'bar')
67
+ end
68
+ end
64
69
  end
65
70
 
66
71
  end
@@ -34,6 +34,15 @@ module Elasticsearch
34
34
  subject.indices.put_alias :index => 'foo', :name => 'bar', :body => { :filter => 'foo' }
35
35
  end
36
36
 
37
+ should "Listify indices" do
38
+ subject.expects(:perform_request).with do |method, url, params, body|
39
+ assert_equal 'foo,bar/_alias/bar%2Fbam', url
40
+ true
41
+ end.returns(FakeResponse.new)
42
+
43
+ subject.indices.put_alias :index => ['foo', 'bar'], :name => 'bar/bam', :body => {}
44
+ end
45
+
37
46
  should "URL-escape the parts" do
38
47
  subject.expects(:perform_request).with do |method, url, params, body|
39
48
  assert_equal 'foo%5Ebar/_alias/bar%2Fbam', url
@@ -59,6 +59,15 @@ module Elasticsearch
59
59
  subject.nodes.info :format => 'yaml'
60
60
  end
61
61
 
62
+ should "encode metrics" do
63
+ subject.expects(:perform_request).with do |method, url, params, body|
64
+ assert_equal '_nodes/http,network', url
65
+ assert_nil params[:metric]
66
+ true
67
+ end.returns(FakeResponse.new)
68
+
69
+ subject.nodes.info :metric => ['http', 'network']
70
+ end
62
71
  end
63
72
 
64
73
  end
@@ -11,8 +11,7 @@ module Elasticsearch
11
11
  subject.expects(:perform_request).with do |method, url, params, body|
12
12
  assert_equal 'GET', method
13
13
  assert_equal '_search/scroll', url
14
- assert_equal 'cXVlcn...', params[:scroll_id]
15
- assert_nil body
14
+ assert_equal 'cXVlcn...', body
16
15
  true
17
16
  end.returns(FakeResponse.new)
18
17
 
@@ -2,39 +2,42 @@ require 'test_helper'
2
2
 
3
3
  module Elasticsearch
4
4
  module Test
5
- class TermvectorTest < ::Test::Unit::TestCase
5
+ class TermvectorsTest < ::Test::Unit::TestCase
6
6
 
7
- context "Termvector" do
7
+ context "Termvectors" do
8
8
  subject { FakeClient.new }
9
9
 
10
10
  should "require the :index argument" do
11
11
  assert_raise ArgumentError do
12
- subject.termvector :type => 'bar', :id => '1'
12
+ subject.termvectors :type => 'bar', :id => '1'
13
13
  end
14
14
  end
15
15
 
16
16
  should "require the :type argument" do
17
17
  assert_raise ArgumentError do
18
- subject.termvector :index => 'foo', :id => '1'
19
- end
20
- end
21
-
22
- should "require the :id argument" do
23
- assert_raise ArgumentError do
24
- subject.termvector :index => 'foo', :type => 'bar'
18
+ subject.termvectors :index => 'foo', :id => '1'
25
19
  end
26
20
  end
27
21
 
28
22
  should "perform correct request" do
29
23
  subject.expects(:perform_request).with do |method, url, params, body|
30
24
  assert_equal 'GET', method
31
- assert_equal 'foo/bar/123/_termvector', url
25
+ assert_equal 'foo/bar/123/_termvectors', url
32
26
  assert_equal Hash.new, params
33
27
  assert_equal Hash.new, body
34
28
  true
35
29
  end.returns(FakeResponse.new)
36
30
 
37
- subject.termvector :index => 'foo', :type => 'bar', :id => '123', :body => {}
31
+ subject.termvectors :index => 'foo', :type => 'bar', :id => '123', :body => {}
32
+ end
33
+
34
+ should "be aliased to singular for older versions" do
35
+ subject.expects(:perform_request).with do |method, url, params, body|
36
+ assert_equal 'foo/bar/123/_termvector', url
37
+ true
38
+ end.returns(FakeResponse.new)
39
+
40
+ subject.termvector :index => 'foo', :type => 'bar', :id => '123'
38
41
  end
39
42
 
40
43
  end
@@ -141,6 +141,9 @@ module Elasticsearch
141
141
  end
142
142
 
143
143
  context "__validate_and_extract_params" do
144
+ teardown do
145
+ Elasticsearch::API.settings.clear
146
+ end
144
147
 
145
148
  should "extract valid params from a Hash" do
146
149
  assert_equal( {:foo => 'qux'},
@@ -164,6 +167,25 @@ module Elasticsearch
164
167
  __validate_and_extract_params( { :format => 'yaml' } ) )
165
168
  end
166
169
 
170
+ should "not validate parameters when the option is set" do
171
+ assert_nothing_raised do
172
+ result = __validate_and_extract_params( { :foo => 'q', :bam => 'm' }, [:foo, :bar], { :skip_parameter_validation => true } )
173
+ assert_equal( { :foo => 'q', :bam => 'm' }, result )
174
+ end
175
+ end
176
+
177
+ should "not validate parameters when the module setting is set" do
178
+ assert_nothing_raised do
179
+ Elasticsearch::API.settings[:skip_parameter_validation] = true
180
+ result = __validate_and_extract_params( { :foo => 'q', :bam => 'm' }, [:foo, :bar] )
181
+ assert_equal( { :foo => 'q', :bam => 'm' }, result )
182
+ end
183
+ end
184
+
185
+ should "listify Arrays" do
186
+ result = __validate_and_extract_params( { :foo => ['a', 'b'] }, [:foo] )
187
+ assert_equal( { :foo => 'a,b'}, result )
188
+ end
167
189
  end
168
190
 
169
191
  context "__extract_parts" do