elasticsearch-api 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/README.md +8 -2
  2. data/Rakefile +15 -1
  3. data/elasticsearch-api.gemspec +12 -0
  4. data/lib/{elasticsearch-api → elasticsearch-api.rb} +0 -0
  5. data/lib/elasticsearch/api.rb +9 -0
  6. data/lib/elasticsearch/api/actions/bulk.rb +9 -9
  7. data/lib/elasticsearch/api/actions/cluster/health.rb +12 -12
  8. data/lib/elasticsearch/api/actions/cluster/node_hot_threads.rb +9 -9
  9. data/lib/elasticsearch/api/actions/cluster/node_info.rb +16 -16
  10. data/lib/elasticsearch/api/actions/cluster/node_shutdown.rb +7 -7
  11. data/lib/elasticsearch/api/actions/cluster/node_stats.rb +16 -18
  12. data/lib/elasticsearch/api/actions/cluster/reroute.rb +4 -6
  13. data/lib/elasticsearch/api/actions/cluster/state.rb +12 -12
  14. data/lib/elasticsearch/api/actions/count.rb +9 -9
  15. data/lib/elasticsearch/api/actions/delete.rb +16 -13
  16. data/lib/elasticsearch/api/actions/delete_by_query.rb +15 -14
  17. data/lib/elasticsearch/api/actions/exists.rb +13 -11
  18. data/lib/elasticsearch/api/actions/explain.rb +28 -17
  19. data/lib/elasticsearch/api/actions/get.rb +20 -11
  20. data/lib/elasticsearch/api/actions/get_source.rb +23 -11
  21. data/lib/elasticsearch/api/actions/index.rb +20 -18
  22. data/lib/elasticsearch/api/actions/indices/analyze.rb +12 -13
  23. data/lib/elasticsearch/api/actions/indices/clear_cache.rb +15 -15
  24. data/lib/elasticsearch/api/actions/indices/close.rb +5 -6
  25. data/lib/elasticsearch/api/actions/indices/create.rb +5 -6
  26. data/lib/elasticsearch/api/actions/indices/delete.rb +5 -6
  27. data/lib/elasticsearch/api/actions/indices/delete_alias.rb +5 -6
  28. data/lib/elasticsearch/api/actions/indices/delete_mapping.rb +1 -1
  29. data/lib/elasticsearch/api/actions/indices/delete_template.rb +5 -6
  30. data/lib/elasticsearch/api/actions/indices/delete_warmer.rb +1 -1
  31. data/lib/elasticsearch/api/actions/indices/exists_alias.rb +5 -6
  32. data/lib/elasticsearch/api/actions/indices/exists_type.rb +5 -6
  33. data/lib/elasticsearch/api/actions/indices/flush.rb +9 -9
  34. data/lib/elasticsearch/api/actions/indices/get_alias.rb +5 -6
  35. data/lib/elasticsearch/api/actions/indices/get_aliases.rb +5 -6
  36. data/lib/elasticsearch/api/actions/indices/get_mapping.rb +1 -1
  37. data/lib/elasticsearch/api/actions/indices/get_settings.rb +1 -1
  38. data/lib/elasticsearch/api/actions/indices/get_template.rb +1 -2
  39. data/lib/elasticsearch/api/actions/indices/get_warmer.rb +1 -1
  40. data/lib/elasticsearch/api/actions/indices/open.rb +5 -6
  41. data/lib/elasticsearch/api/actions/indices/optimize.rb +12 -12
  42. data/lib/elasticsearch/api/actions/indices/put_alias.rb +5 -6
  43. data/lib/elasticsearch/api/actions/indices/put_mapping.rb +5 -7
  44. data/lib/elasticsearch/api/actions/indices/put_settings.rb +1 -1
  45. data/lib/elasticsearch/api/actions/indices/put_template.rb +5 -7
  46. data/lib/elasticsearch/api/actions/indices/refresh.rb +5 -6
  47. data/lib/elasticsearch/api/actions/indices/segments.rb +5 -6
  48. data/lib/elasticsearch/api/actions/indices/snapshot_index.rb +5 -6
  49. data/lib/elasticsearch/api/actions/indices/stats.rb +23 -23
  50. data/lib/elasticsearch/api/actions/indices/status.rb +8 -8
  51. data/lib/elasticsearch/api/actions/indices/update_aliases.rb +4 -5
  52. data/lib/elasticsearch/api/actions/indices/validate_query.rb +11 -9
  53. data/lib/elasticsearch/api/actions/mget.rb +21 -11
  54. data/lib/elasticsearch/api/actions/mlt.rb +28 -24
  55. data/lib/elasticsearch/api/actions/msearch.rb +4 -5
  56. data/lib/elasticsearch/api/actions/percolate.rb +7 -6
  57. data/lib/elasticsearch/api/actions/scroll.rb +5 -6
  58. data/lib/elasticsearch/api/actions/search.rb +37 -30
  59. data/lib/elasticsearch/api/actions/suggest.rb +8 -8
  60. data/lib/elasticsearch/api/actions/update.rb +24 -20
  61. data/lib/elasticsearch/api/utils.rb +44 -6
  62. data/lib/elasticsearch/api/version.rb +1 -1
  63. data/test/integration/yaml_test_runner.rb +4 -5
  64. data/test/test_helper.rb +1 -1
  65. data/test/unit/bulk_test.rb +9 -0
  66. data/test/unit/cluster/node_hot_threads_test.rb +9 -0
  67. data/test/unit/create_document_test.rb +9 -0
  68. data/test/unit/delete_document_test.rb +16 -1
  69. data/test/unit/exists_document_test.rb +9 -0
  70. data/test/unit/explain_document_test.rb +9 -0
  71. data/test/unit/get_document_source_test.rb +10 -1
  72. data/test/unit/get_document_test.rb +16 -1
  73. data/test/unit/index_document_test.rb +15 -0
  74. data/test/unit/indices/analyze_test.rb +9 -0
  75. data/test/unit/indices/clear_cache_test.rb +9 -0
  76. data/test/unit/indices/close_test.rb +9 -0
  77. data/test/unit/indices/create_test.rb +9 -0
  78. data/test/unit/indices/delete_alias_test.rb +9 -0
  79. data/test/unit/indices/delete_mapping_test.rb +9 -0
  80. data/test/unit/indices/delete_template_test.rb +9 -0
  81. data/test/unit/indices/delete_test.rb +9 -0
  82. data/test/unit/indices/delete_warmer_test.rb +9 -0
  83. data/test/unit/indices/exists_alias_test.rb +9 -0
  84. data/test/unit/indices/exists_test.rb +9 -0
  85. data/test/unit/indices/exists_type_test.rb +9 -0
  86. data/test/unit/indices/flush_test.rb +9 -0
  87. data/test/unit/indices/get_alias_test.rb +9 -0
  88. data/test/unit/indices/get_aliases_test.rb +9 -0
  89. data/test/unit/indices/get_mapping_test.rb +9 -0
  90. data/test/unit/indices/get_settings_test.rb +9 -0
  91. data/test/unit/indices/get_template_test.rb +10 -6
  92. data/test/unit/indices/get_warmer_test.rb +9 -0
  93. data/test/unit/indices/open_test.rb +9 -0
  94. data/test/unit/indices/optimize_test.rb +9 -0
  95. data/test/unit/indices/put_alias_test.rb +9 -0
  96. data/test/unit/indices/put_mapping_test.rb +9 -0
  97. data/test/unit/indices/put_settings_test.rb +9 -0
  98. data/test/unit/indices/put_template_test.rb +9 -0
  99. data/test/unit/indices/put_warmer_test.rb +9 -0
  100. data/test/unit/indices/refresh_test.rb +9 -0
  101. data/test/unit/indices/segments_test.rb +9 -0
  102. data/test/unit/indices/snapshot_index_test.rb +9 -0
  103. data/test/unit/indices/stats_test.rb +9 -0
  104. data/test/unit/indices/status_test.rb +9 -0
  105. data/test/unit/indices/validate_query_test.rb +9 -0
  106. data/test/unit/mget_test.rb +9 -0
  107. data/test/unit/mlt_test.rb +9 -0
  108. data/test/unit/msearch_test.rb +9 -0
  109. data/test/unit/percolate_test.rb +9 -0
  110. data/test/unit/search_test.rb +16 -1
  111. data/test/unit/suggest_test.rb +9 -0
  112. data/test/unit/update_document_test.rb +16 -1
  113. data/test/unit/utils_test.rb +34 -5
  114. metadata +161 -44
  115. checksums.yaml +0 -7
data/README.md CHANGED
@@ -36,6 +36,8 @@ or install it from a source code checkout:
36
36
  The library is designed as a group of standalone Ruby modules, which can be mixed into a class
37
37
  providing connection to Elasticsearch -- an Elasticsearch client.
38
38
 
39
+ ### Usage with the `elasticsearch` gem
40
+
39
41
  **When you use the client from the [`elasticsearch-ruby`](https://github.com/elasticsearch/elasticsearch-ruby/) package,
40
42
  the library modules have been already included**, so you just call the API methods:
41
43
 
@@ -51,6 +53,10 @@ client.search body: { query: { match: { title: 'test' } } }
51
53
  # => {"took"=>2, ..., "hits"=>{"total":5, ...}}
52
54
  ```
53
55
 
56
+ Full documentation is available at <http://rubydoc.info/gems/elasticsearch-api>.
57
+
58
+ ### Usage with a custom client
59
+
54
60
  When you want to mix the library into you own client, it must conform to a following _contract_:
55
61
 
56
62
  * It responds to a `perform_request(method, path, params, body)` method,
@@ -90,7 +96,7 @@ p client.index index: 'myindex', type: 'mytype', id: 'custom', body: { title: "I
90
96
  # => "{"ok":true, ... }"
91
97
  ```
92
98
 
93
- ## Using JSON Builders
99
+ ### Using JSON Builders
94
100
 
95
101
  Instead of passing the `:body` argument as a Ruby _Hash_, you can pass it as a _String_, potentially
96
102
  taking advantage of JSON builders such as [JBuilder](https://github.com/rails/jbuilder) or
@@ -118,7 +124,7 @@ client.search index: 'myindex', body: json
118
124
  # => {"took"=>21, ..., "hits"=>{"total"=>1, "hits"=>[{ "_source"=>{"title"=>"Test 1", ...}}]}}
119
125
  ```
120
126
 
121
- ## Using Hash Wrappers
127
+ ### Using Hash Wrappers
122
128
 
123
129
  For a more comfortable access to response properties, you may wrap it in one of the _Hash_ "object access"
124
130
  wrappers, such as [`Hashie::Mash`](https://github.com/intridea/hashie):
data/Rakefile CHANGED
@@ -8,7 +8,19 @@ task :test => 'test:unit'
8
8
 
9
9
  require 'rake/testtask'
10
10
  namespace :test do
11
+ task :ci_reporter do
12
+ ENV['CI_REPORTS'] ||= 'tmp/reports'
13
+ if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
14
+ require 'ci/reporter/rake/test_unit'
15
+ Rake::Task['ci:setup:testunit'].invoke
16
+ else
17
+ require 'ci/reporter/rake/minitest'
18
+ Rake::Task['ci:setup:minitest'].invoke
19
+ end
20
+ end
21
+
11
22
  Rake::TestTask.new(:unit) do |test|
23
+ Rake::Task['test:ci_reporter'].invoke if ENV['CI']
12
24
  test.libs << 'lib' << 'test'
13
25
  test.test_files = FileList["test/unit/**/*_test.rb"]
14
26
  # test.verbose = true
@@ -16,13 +28,15 @@ namespace :test do
16
28
  end
17
29
 
18
30
  Rake::TestTask.new(:integration) do |test|
31
+ Rake::Task['test:ci_reporter'].invoke if ENV['CI']
19
32
  test.libs << 'lib' << 'test'
20
33
  test.test_files = FileList["test/integration/yaml_test_runner.rb", "test/integration/**/*_test.rb"]
21
34
  end
22
35
 
23
36
  Rake::TestTask.new(:all) do |test|
37
+ Rake::Task['test:ci_reporter'].invoke if ENV['CI']
24
38
  test.libs << 'lib' << 'test'
25
- test.test_files = FileList["test/unit/**/*_test.rb", "test/integration/**/*_test.rb"]
39
+ test.test_files = FileList["test/unit/**/*_test.rb", "test/integration/**/*_test.rb", "test/integration/yaml_test_runner.rb"]
26
40
  end
27
41
 
28
42
  namespace :server do
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency "bundler", "> 1"
26
26
  s.add_development_dependency "rake"
27
27
 
28
+ s.add_development_dependency "elasticsearch"
28
29
  s.add_development_dependency "elasticsearch-transport"
29
30
 
30
31
  s.add_development_dependency "ansi"
@@ -33,16 +34,27 @@ Gem::Specification.new do |s|
33
34
  s.add_development_dependency "turn"
34
35
  s.add_development_dependency "yard"
35
36
  s.add_development_dependency "ruby-prof"
37
+ s.add_development_dependency "pry"
38
+ s.add_development_dependency "ci_reporter"
36
39
 
40
+ # Gems for testing integrations
37
41
  s.add_development_dependency "multi_json"
38
42
  s.add_development_dependency "jbuilder"
39
43
  s.add_development_dependency "jsonify"
40
44
  s.add_development_dependency "hashie"
45
+ s.add_development_dependency "escape_utils"
46
+
47
+ # Prevent unit test failures on Ruby 1.8
48
+ if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
49
+ s.add_development_dependency "test-unit", '~> 2'
50
+ s.add_development_dependency "activesupport", '~> 3'
51
+ end
41
52
 
42
53
  if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
43
54
  s.add_development_dependency "simplecov"
44
55
  s.add_development_dependency "cane"
45
56
  s.add_development_dependency "require-prof"
57
+ s.add_development_dependency "coveralls"
46
58
  end
47
59
 
48
60
  s.description = <<-DESC.gsub(/^ /, '')
File without changes
@@ -1,3 +1,4 @@
1
+ require "cgi"
1
2
  require "multi_json"
2
3
 
3
4
  require "elasticsearch/api/version"
@@ -9,6 +10,14 @@ Dir[ File.expand_path('../api/namespace/**/*.rb', __FILE__) ].each { |f| require
9
10
 
10
11
  module Elasticsearch
11
12
  module API
13
+ COMMON_PARAMS = [
14
+ :ignore, # Client specific parameters
15
+ :index, :type, :id, # :index/:type/:id
16
+ :body, # Request body
17
+ :node_id, # Cluster APIs
18
+ :name, # Template, warmer APIs
19
+ :pretty # Pretty-print the response
20
+ ]
12
21
 
13
22
  # Auto-include all namespaces in the receiver
14
23
  #
@@ -46,16 +46,16 @@ module Elasticsearch
46
46
  # @see http://elasticsearch.org/guide/reference/api/bulk/
47
47
  #
48
48
  def bulk(arguments={})
49
+ valid_params = [
50
+ :consistency,
51
+ :refresh,
52
+ :replication,
53
+ :type ]
54
+
49
55
  method = 'POST'
50
- path = [arguments[:index], arguments[:type], '_bulk'].compact.join('/')
51
- params = arguments.select do |k,v|
52
- [ :consistency,
53
- :refresh,
54
- :replication,
55
- :type ].include?(k)
56
- end
57
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
58
- params = Hash[params] unless params.is_a?(Hash)
56
+ path = Utils.__pathify Utils.__escape(arguments[:index]), Utils.__escape(arguments[:type]), '_bulk'
57
+
58
+ params = Utils.__validate_and_extract_params arguments, valid_params
59
59
  body = arguments[:body]
60
60
 
61
61
  if body.is_a? Array
@@ -26,20 +26,20 @@ module Elasticsearch
26
26
  # @see http://elasticsearch.org/guide/reference/api/admin-cluster-health/
27
27
  #
28
28
  def health(arguments={})
29
+ valid_params = [
30
+ :level,
31
+ :local,
32
+ :master_timeout,
33
+ :timeout,
34
+ :wait_for_active_shards,
35
+ :wait_for_nodes,
36
+ :wait_for_relocating_shards,
37
+ :wait_for_status ]
38
+
29
39
  method = 'GET'
30
40
  path = "_cluster/health"
31
- params = arguments.select do |k,v|
32
- [ :level,
33
- :local,
34
- :master_timeout,
35
- :timeout,
36
- :wait_for_active_shards,
37
- :wait_for_nodes,
38
- :wait_for_relocating_shards,
39
- :wait_for_status ].include?(k)
40
- end
41
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
42
- params = Hash[params] unless params.is_a?(Hash)
41
+
42
+ params = Utils.__validate_and_extract_params arguments, valid_params
43
43
  body = nil
44
44
 
45
45
  perform_request(method, path, params, body).body
@@ -26,16 +26,16 @@ module Elasticsearch
26
26
  # @see http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-hot-threads/
27
27
  #
28
28
  def node_hot_threads(arguments={})
29
+ valid_params = [
30
+ :interval,
31
+ :snapshots,
32
+ :threads,
33
+ :type ]
34
+
29
35
  method = 'GET'
30
- path = "_cluster/nodes/#{arguments[:node_id]}/hot_threads".squeeze('/')
31
- params = arguments.select do |k,v|
32
- [ :interval,
33
- :snapshots,
34
- :threads,
35
- :type ].include?(k)
36
- end
37
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
38
- params = Hash[params] unless params.is_a?(Hash)
36
+ path = Utils.__pathify '_cluster/nodes', Utils.__listify(arguments[:node_id]), 'hot_threads'
37
+
38
+ params = Utils.__validate_and_extract_params arguments, valid_params
39
39
  body = nil
40
40
 
41
41
  perform_request(method, path, params, body).body
@@ -32,23 +32,23 @@ module Elasticsearch
32
32
  # @see http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/
33
33
  #
34
34
  def node_info(arguments={})
35
+ valid_params = [
36
+ :all,
37
+ :clear,
38
+ :http,
39
+ :jvm,
40
+ :network,
41
+ :os,
42
+ :plugin,
43
+ :process,
44
+ :settings,
45
+ :thread_pool,
46
+ :transport ]
47
+
35
48
  method = 'GET'
36
- path = Utils.__pathify( '_cluster/nodes', Utils.__listify(arguments[:node_id]) )
37
- params = arguments.select do |k,v|
38
- [ :all,
39
- :clear,
40
- :http,
41
- :jvm,
42
- :network,
43
- :os,
44
- :plugin,
45
- :process,
46
- :settings,
47
- :thread_pool,
48
- :transport ].include?(k)
49
- end
50
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
51
- params = Hash[params] unless params.is_a?(Hash)
49
+ path = Utils.__pathify '_cluster/nodes', Utils.__listify(arguments[:node_id])
50
+
51
+ params = Utils.__validate_and_extract_params arguments, valid_params
52
52
  body = nil
53
53
 
54
54
  perform_request(method, path, params, body).body
@@ -18,14 +18,14 @@ module Elasticsearch
18
18
  # @see http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/
19
19
  #
20
20
  def node_shutdown(arguments={})
21
+ valid_params = [
22
+ :delay,
23
+ :exit ]
24
+
21
25
  method = 'POST'
22
- path = Utils.__pathify( '_cluster/nodes', Utils.__listify(arguments[:node_id]), '_shutdown' )
23
- params = arguments.select do |k,v|
24
- [ :delay,
25
- :exit ].include?(k)
26
- end
27
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
28
- params = Hash[params] unless params.is_a?(Hash)
26
+ path = Utils.__pathify '_cluster/nodes', Utils.__listify(arguments[:node_id]), '_shutdown'
27
+
28
+ params = Utils.__validate_and_extract_params arguments, valid_params
29
29
  body = nil
30
30
 
31
31
  perform_request(method, path, params, body).body
@@ -31,12 +31,26 @@ module Elasticsearch
31
31
  # @see http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/
32
32
  #
33
33
  def node_stats(arguments={})
34
+ valid_params = [
35
+ :all,
36
+ :clear,
37
+ :fields,
38
+ :fs,
39
+ :http,
40
+ :indices,
41
+ :jvm,
42
+ :network,
43
+ :os,
44
+ :process,
45
+ :thread_pool,
46
+ :transport ]
47
+
34
48
  method = 'GET'
35
49
 
36
50
  case
37
51
  # Field data metric for the `indices` metric family
38
52
  when arguments[:indices] && arguments[:metric] == 'fielddata'
39
- path = Utils.__pathify( '_nodes', Utils.__listify(arguments[:node_id]), 'stats/indices/fielddata' )
53
+ path = Utils.__pathify '_nodes', Utils.__listify(arguments[:node_id]), 'stats/indices/fielddata'
40
54
  params = { :fields => Utils.__listify(arguments[:fields]) }
41
55
 
42
56
  # `indices` metric family incl. a metric
@@ -47,23 +61,7 @@ module Elasticsearch
47
61
  else
48
62
  path = Utils.__pathify( '_nodes', Utils.__listify(arguments[:node_id]), 'stats' )
49
63
 
50
- params = arguments.select do |k,v|
51
- [ :all,
52
- :clear,
53
- :fields,
54
- :fs,
55
- :http,
56
- :indices,
57
- :jvm,
58
- :network,
59
- :os,
60
- :process,
61
- :thread_pool,
62
- :transport ].include?(k)
63
- end
64
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
65
- params = Hash[params] unless params.is_a?(Hash)
66
-
64
+ params = Utils.__validate_and_extract_params arguments, valid_params
67
65
  params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
68
66
  end
69
67
 
@@ -26,14 +26,12 @@ module Elasticsearch
26
26
  # @see http://elasticsearch.org/guide/reference/api/admin-cluster-reroute/
27
27
  #
28
28
  def reroute(arguments={})
29
+ valid_params = [ :dry_run, :filter_metadata ]
30
+
29
31
  method = 'POST'
30
32
  path = "_cluster/reroute"
31
- params = arguments.select do |k,v|
32
- [ :dry_run,
33
- :filter_metadata ].include?(k)
34
- end
35
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
36
- params = Hash[params] unless params.is_a?(Hash)
33
+
34
+ params = Utils.__validate_and_extract_params arguments, valid_params
37
35
  body = arguments[:body] || {}
38
36
 
39
37
  perform_request(method, path, params, body).body
@@ -23,20 +23,20 @@ module Elasticsearch
23
23
  # @see http://elasticsearch.org/guide/reference/api/admin-cluster-state/
24
24
  #
25
25
  def state(arguments={})
26
+ valid_params = [
27
+ :filter_blocks,
28
+ :filter_index_templates,
29
+ :filter_indices,
30
+ :filter_metadata,
31
+ :filter_nodes,
32
+ :filter_routing_table,
33
+ :local,
34
+ :master_timeout ]
35
+
26
36
  method = 'GET'
27
37
  path = "_cluster/state"
28
- params = arguments.select do |k,v|
29
- [ :filter_blocks,
30
- :filter_index_templates,
31
- :filter_indices,
32
- :filter_metadata,
33
- :filter_nodes,
34
- :filter_routing_table,
35
- :local,
36
- :master_timeout ].include?(k)
37
- end
38
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
39
- params = Hash[params] unless params.is_a?(Hash)
38
+
39
+ params = Utils.__validate_and_extract_params arguments, valid_params
40
40
  body = nil
41
41
 
42
42
  perform_request(method, path, params, body).body
@@ -26,17 +26,17 @@ module Elasticsearch
26
26
  # @see http://elasticsearch.org/guide/reference/api/count/
27
27
  #
28
28
  def count(arguments={})
29
+ valid_params = [
30
+ :ignore_indices,
31
+ :min_score,
32
+ :preference,
33
+ :routing,
34
+ :source ]
35
+
29
36
  method = 'GET'
30
37
  path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_count' )
31
- params = arguments.select do |k,v|
32
- [ :ignore_indices,
33
- :min_score,
34
- :preference,
35
- :routing,
36
- :source ].include?(k)
37
- end
38
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
39
- params = Hash[params] unless params.is_a?(Hash)
38
+
39
+ params = Utils.__validate_and_extract_params arguments, valid_params
40
40
  body = arguments[:body]
41
41
 
42
42
  perform_request(method, path, params, body).body
@@ -32,20 +32,23 @@ module Elasticsearch
32
32
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
33
33
  raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
34
34
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
35
+
36
+ valid_params = [
37
+ :consistency,
38
+ :parent,
39
+ :refresh,
40
+ :replication,
41
+ :routing,
42
+ :timeout,
43
+ :version,
44
+ :version_type ]
45
+
35
46
  method = 'DELETE'
36
- path = Utils.__pathify( arguments[:index], arguments[:type], arguments[:id] )
37
- params = arguments.select do |k,v|
38
- [ :consistency,
39
- :parent,
40
- :refresh,
41
- :replication,
42
- :routing,
43
- :timeout,
44
- :version,
45
- :version_type ].include?(k)
46
- end
47
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
48
- params = Hash[params] unless params.is_a?(Hash)
47
+ path = Utils.__pathify Utils.__escape(arguments[:index]),
48
+ Utils.__escape(arguments[:type]),
49
+ Utils.__escape(arguments[:id])
50
+
51
+ params = Utils.__validate_and_extract_params arguments, valid_params
49
52
  body = nil
50
53
 
51
54
  perform_request(method, path, params, body).body