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
@@ -48,16 +48,18 @@ module Elasticsearch
48
48
  # @see http://www.elasticsearch.org/guide/reference/api/validate/
49
49
  #
50
50
  def validate_query(arguments={})
51
+ valid_params = [
52
+ :q,
53
+ :explain,
54
+ :ignore_indices,
55
+ :source ]
56
+
51
57
  method = 'GET'
52
- path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_validate/query' )
53
- params = arguments.select do |k,v|
54
- [ :q,
55
- :explain,
56
- :ignore_indices,
57
- :source ].include?(k)
58
- end
59
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
60
- params = Hash[params] unless params.is_a?(Hash)
58
+ path = Utils.__pathify Utils.__listify(arguments[:index]),
59
+ Utils.__listify(arguments[:type]),
60
+ '_validate/query'
61
+
62
+ params = Utils.__validate_and_extract_params arguments, valid_params
61
63
  body = arguments[:body]
62
64
 
63
65
  perform_request(method, path, params, body).body
@@ -36,23 +36,33 @@ module Elasticsearch
36
36
  # @option arguments [Boolean] :realtime Specify whether to perform the operation in realtime or search mode
37
37
  # @option arguments [Boolean] :refresh Refresh the shard containing the document before performing the operation
38
38
  # @option arguments [String] :routing Specific routing value
39
+ # @option arguments [String] :_source Specify whether the _source field should be returned,
40
+ # or a list of fields to return
41
+ # @option arguments [String] :_source_exclude A list of fields to exclude from the returned _source field
42
+ # @option arguments [String] :_source_include A list of fields to extract and return from the _source field
39
43
  #
40
44
  # @see http://elasticsearch.org/guide/reference/api/multi-get/
41
45
  #
42
46
  def mget(arguments={})
43
47
  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
48
+
49
+ valid_params = [
50
+ :fields,
51
+ :parent,
52
+ :preference,
53
+ :realtime,
54
+ :refresh,
55
+ :routing,
56
+ :_source,
57
+ :_source_include,
58
+ :_source_exclude ]
59
+
44
60
  method = 'GET'
45
- path = Utils.__pathify( arguments[:index], arguments[:type], '_mget' )
46
- params = arguments.select do |k,v|
47
- [ :fields,
48
- :parent,
49
- :preference,
50
- :realtime,
51
- :refresh,
52
- :routing ].include?(k)
53
- end
54
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
55
- params = Hash[params] unless params.is_a?(Hash)
61
+ path = Utils.__pathify Utils.__escape(arguments[:index]),
62
+ Utils.__escape(arguments[:type]),
63
+ '_mget'
64
+
65
+ params = Utils.__validate_and_extract_params arguments, valid_params
56
66
  body = arguments[:body]
57
67
 
58
68
  params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
@@ -47,31 +47,35 @@ module Elasticsearch
47
47
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
48
48
  raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
49
49
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
50
+
51
+ valid_params = [
52
+ :boost_terms,
53
+ :max_doc_freq,
54
+ :max_query_terms,
55
+ :max_word_len,
56
+ :min_doc_freq,
57
+ :min_term_freq,
58
+ :min_word_len,
59
+ :mlt_fields,
60
+ :percent_terms_to_match,
61
+ :routing,
62
+ :search_from,
63
+ :search_indices,
64
+ :search_query_hint,
65
+ :search_scroll,
66
+ :search_size,
67
+ :search_source,
68
+ :search_type,
69
+ :search_types,
70
+ :stop_words ]
71
+
50
72
  method = 'GET'
51
- path = Utils.__pathify( arguments[:index], arguments[:type], arguments[:id], '_mlt' )
52
- params = arguments.select do |k,v|
53
- [ :boost_terms,
54
- :max_doc_freq,
55
- :max_query_terms,
56
- :max_word_len,
57
- :min_doc_freq,
58
- :min_term_freq,
59
- :min_word_len,
60
- :mlt_fields,
61
- :percent_terms_to_match,
62
- :routing,
63
- :search_from,
64
- :search_indices,
65
- :search_query_hint,
66
- :search_scroll,
67
- :search_size,
68
- :search_source,
69
- :search_type,
70
- :search_types,
71
- :stop_words ].include?(k)
72
- end
73
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
74
- params = Hash[params] unless params.is_a?(Hash)
73
+ path = Utils.__pathify Utils.__escape(arguments[:index]),
74
+ Utils.__escape(arguments[:type]),
75
+ Utils.__escape(arguments[:id]),
76
+ '_mlt'
77
+
78
+ params = Utils.__validate_and_extract_params arguments, valid_params
75
79
 
76
80
  [:mlt_fields, :search_indices, :search_types, :stop_words].each do |name|
77
81
  params[name] = Utils.__listify(params[name]) if params[name]
@@ -37,13 +37,12 @@ module Elasticsearch
37
37
  #
38
38
  def msearch(arguments={})
39
39
  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
40
+ valid_params = [ :search_type ]
41
+
40
42
  method = 'GET'
41
43
  path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_msearch' )
42
- params = arguments.select do |k,v|
43
- [ :search_type ].include?(k)
44
- end
45
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
46
- params = Hash[params] unless params.is_a?(Hash)
44
+
45
+ params = Utils.__validate_and_extract_params arguments, valid_params
47
46
  body = arguments[:body]
48
47
 
49
48
  case
@@ -41,13 +41,14 @@ module Elasticsearch
41
41
  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
42
42
  arguments[:type] ||= 'document'
43
43
 
44
+ valid_params = [ :prefer_local ]
45
+
44
46
  method = 'GET'
45
- path = "#{arguments[:index]}/#{arguments[:type]}/_percolate"
46
- params = arguments.select do |k,v|
47
- [ :prefer_local ].include?(k)
48
- end
49
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
50
- params = Hash[params] unless params.is_a?(Hash)
47
+ path = Utils.__pathify Utils.__escape(arguments[:index]),
48
+ Utils.__escape(arguments[:type]),
49
+ '_percolate'
50
+
51
+ params = Utils.__validate_and_extract_params arguments, valid_params
51
52
  body = arguments[:body]
52
53
 
53
54
  perform_request(method, path, params, body).body
@@ -29,12 +29,11 @@ module Elasticsearch
29
29
  def scroll(arguments={})
30
30
  method = 'GET'
31
31
  path = "_search/scroll"
32
- params = arguments.select do |k,v|
33
- [ :scroll,
34
- :scroll_id ].include?(k)
35
- end
36
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
37
- params = Hash[params] unless params.is_a?(Hash)
32
+ valid_params = [
33
+ :scroll,
34
+ :scroll_id ]
35
+
36
+ params = Utils.__validate_and_extract_params arguments, valid_params
38
37
  body = arguments[:body]
39
38
 
40
39
  perform_request(method, path, params, body).body
@@ -86,6 +86,10 @@ module Elasticsearch
86
86
  # @option arguments [List] :sort A comma-separated list of <field>:<direction> pairs
87
87
  # @option arguments [String] :source The URL-encoded request definition using the Query DSL
88
88
  # (instead of using request body)
89
+ # @option arguments [String] :_source Specify whether the _source field should be returned,
90
+ # or a list of fields to return
91
+ # @option arguments [String] :_source_exclude A list of fields to exclude from the returned _source field
92
+ # @option arguments [String] :_source_include A list of fields to extract and return from the _source field
89
93
  # @option arguments [List] :stats Specific 'tag' of the request for logging and statistical purposes
90
94
  # @option arguments [String] :suggest_field Specify which field to use for suggestions
91
95
  # @option arguments [String] :suggest_mode Specify suggest mode (options: missing, popular, always)
@@ -102,38 +106,41 @@ module Elasticsearch
102
106
  def search(arguments={})
103
107
  arguments[:index] = '_all' if ! arguments[:index] && arguments[:type]
104
108
 
109
+ valid_params = [
110
+ :analyzer,
111
+ :analyze_wildcard,
112
+ :default_operator,
113
+ :df,
114
+ :explain,
115
+ :fields,
116
+ :from,
117
+ :ignore_indices,
118
+ :indices_boost,
119
+ :lenient,
120
+ :lowercase_expanded_terms,
121
+ :preference,
122
+ :q,
123
+ :routing,
124
+ :scroll,
125
+ :search_type,
126
+ :size,
127
+ :sort,
128
+ :source,
129
+ :_source,
130
+ :_source_include,
131
+ :_source_exclude,
132
+ :stats,
133
+ :suggest_field,
134
+ :suggest_mode,
135
+ :suggest_size,
136
+ :suggest_text,
137
+ :timeout,
138
+ :version ]
139
+
105
140
  method = 'GET'
106
141
  path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_search' )
107
- params = arguments.select do |k,v|
108
- [ :analyzer,
109
- :analyze_wildcard,
110
- :default_operator,
111
- :df,
112
- :explain,
113
- :fields,
114
- :from,
115
- :ignore_indices,
116
- :indices_boost,
117
- :lenient,
118
- :lowercase_expanded_terms,
119
- :preference,
120
- :q,
121
- :routing,
122
- :scroll,
123
- :search_type,
124
- :size,
125
- :sort,
126
- :source,
127
- :stats,
128
- :suggest_field,
129
- :suggest_mode,
130
- :suggest_size,
131
- :suggest_text,
132
- :timeout,
133
- :version ].include?(k)
134
- end
135
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
136
- params = Hash[params] unless params.is_a?(Hash)
142
+
143
+ params = Utils.__validate_and_extract_params arguments, valid_params
137
144
  body = arguments[:body]
138
145
 
139
146
  params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
@@ -27,16 +27,16 @@ module Elasticsearch
27
27
  # @see http://elasticsearch.org/guide/reference/api/search/suggest/
28
28
  #
29
29
  def suggest(arguments={})
30
+ valid_params = [
31
+ :ignore_indices,
32
+ :preference,
33
+ :routing,
34
+ :source ]
35
+
30
36
  method = 'POST'
31
37
  path = Utils.__pathify( Utils.__listify(arguments[:index]), '_suggest' )
32
- params = arguments.select do |k,v|
33
- [ :ignore_indices,
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
@@ -65,27 +65,31 @@ module Elasticsearch
65
65
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
66
66
  raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
67
67
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
68
+
69
+ valid_params = [
70
+ :consistency,
71
+ :fields,
72
+ :lang,
73
+ :parent,
74
+ :percolate,
75
+ :refresh,
76
+ :replication,
77
+ :retry_on_conflict,
78
+ :routing,
79
+ :script,
80
+ :timeout,
81
+ :timestamp,
82
+ :ttl,
83
+ :version,
84
+ :version_type ]
85
+
68
86
  method = 'POST'
69
- path = Utils.__pathify( arguments[:index], arguments[:type], arguments[:id], '_update' )
70
- params = arguments.select do |k,v|
71
- [ :consistency,
72
- :fields,
73
- :lang,
74
- :parent,
75
- :percolate,
76
- :refresh,
77
- :replication,
78
- :retry_on_conflict,
79
- :routing,
80
- :script,
81
- :timeout,
82
- :timestamp,
83
- :ttl,
84
- :version,
85
- :version_type ].include?(k)
86
- end
87
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
88
- params = Hash[params] unless params.is_a?(Hash)
87
+ path = Utils.__pathify Utils.__escape(arguments[:index]),
88
+ Utils.__escape(arguments[:type]),
89
+ Utils.__escape(arguments[:id]),
90
+ '_update'
91
+
92
+ params = Utils.__validate_and_extract_params arguments, valid_params
89
93
  body = arguments[:body]
90
94
 
91
95
  params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
@@ -8,14 +8,15 @@ module Elasticsearch
8
8
  # URL-escape a string
9
9
  #
10
10
  # @example
11
+ # __escape('foo/bar') # => 'foo%2Fbar'
11
12
  # __escape('bar^bam') # => 'bar%5Ebam'
12
13
  #
13
14
  # @api private
14
15
  def __escape(string)
15
- URI.encode(string.to_s)
16
+ defined?(EscapeUtils) ? EscapeUtils.escape_url(string.to_s) : CGI.escape(string.to_s)
16
17
  end
17
18
 
18
- # Create a "list" of values from arguments, ignoring nil values
19
+ # Create a "list" of values from arguments, ignoring nil values and encoding special characters.
19
20
  #
20
21
  # @example Create a list from array
21
22
  # __listify(['A','B']) # => 'A,B'
@@ -23,13 +24,22 @@ module Elasticsearch
23
24
  # @example Create a list from arguments
24
25
  # __listify('A','B') # => 'A,B'
25
26
  #
27
+ # @example Escape values
28
+ # __listify('foo','bar^bam') # => 'foo,bar%5Ebam'
29
+ #
26
30
  # @api private
27
31
  def __listify(*list)
28
- Array(list).flatten.compact.join(',')
32
+ # require 'pry'
33
+ # binding.pry
34
+ Array(list).flatten.
35
+ map { |e| e.respond_to?(:split) ? e.split(',') : e }.
36
+ flatten.
37
+ compact.
38
+ map { |e| __escape(e) }.
39
+ join(',')
29
40
  end
30
41
 
31
- # Create a path (URL part) from arguments, ignoring nil values and empty strings,
32
- # and encoding special characters
42
+ # Create a path (URL part) from arguments, ignoring nil values and empty strings.
33
43
  #
34
44
  # @example Create a path from array
35
45
  # __pathify(['foo', '', nil, 'bar']) # => 'foo/bar'
@@ -45,7 +55,6 @@ module Elasticsearch
45
55
  Array(segments).flatten.
46
56
  compact.
47
57
  reject { |s| s.to_s =~ /^\s*$/ }.
48
- map { |s| __escape(s) }.
49
58
  join('/').
50
59
  squeeze('/')
51
60
  end
@@ -91,6 +100,35 @@ module Elasticsearch
91
100
  payload = payload.join("\n")
92
101
  end
93
102
 
103
+ # Validates the argument Hash against common and valid API parameters
104
+ #
105
+ # @param arguments [Hash] Hash of arguments to verify and extract, **with symbolized keys**
106
+ # @param valid_params [Array<Symbol>] An array of symbols with valid keys
107
+ #
108
+ # @return [Hash] Return whitelisted Hash
109
+ # @raise [ArgumentError] If the arguments Hash contains invalid keys
110
+ #
111
+ # @example Extract parameters
112
+ # __validate_and_extract_params { :foo => 'qux' }, [:foo, :bar]
113
+ # # => { :foo => 'qux' }
114
+ #
115
+ # @example Raise an exception for invalid parameters
116
+ # __validate_and_extract_params { :foo => 'qux', :bam => 'mux' }, [:foo, :bar]
117
+ # # ArgumentError: "URL parameter 'bam' is not supported"
118
+ #
119
+ # @api private
120
+ #
121
+ def __validate_and_extract_params(arguments, valid_params=[])
122
+ arguments.each do |k,v|
123
+ raise ArgumentError, "URL parameter '#{k}' is not supported" \
124
+ unless valid_params.include?(k) || COMMON_PARAMS.include?(k)
125
+ end
126
+
127
+ params = arguments.select { |k,v| valid_params.include?(k) }
128
+ params = Hash[params] unless params.is_a?(Hash) # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
129
+ params
130
+ end
131
+
94
132
  extend self
95
133
  end
96
134
  end
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module API
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end