elasticsearch-api 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62247808bb72f7ae656b190ea047eeb8a93160f2
4
- data.tar.gz: 0ab2745690ffc9e0e5243b050ade10dea4fec177
3
+ metadata.gz: 8c84503f7051b6272a5d1bcd9010d84b1b3fcf6c
4
+ data.tar.gz: 715eb2f3af37710770a9247872f8c55c23d5d144
5
5
  SHA512:
6
- metadata.gz: 04845dd1ec5918fdd884ced7eed2772f15e3e73b56462d8e4859964e55a099af166dd9cf7df5715141aa69a286fbdb91bbe7360f4133d60b9f38953e86e0c1b5
7
- data.tar.gz: 4e0f8f9f1e1d4853d48acc0f583af99b8d84693af566e18eb8f775fc0e3b0b1e731964a54bf40391d9d5b24f784a093f25efc5be593bfb637a70722530893130
6
+ metadata.gz: 9fdf7d52c842acc1f962601abf18277fce30051b7efd87233881d77d09d39647a0ec0f70e3d623cedf277166bc24e6720b9496a44a5ecc8abc92ead6e3c8b021
7
+ data.tar.gz: 2641055eac4b624a1422298da436b5f1e3d62c69becd67b67c9dcac9ee532159ce9c7a59d1cdcafe9a2186a9f9f4392b93c3b7116aa9781262986dc2727891f1
@@ -22,7 +22,8 @@ module Elasticsearch
22
22
  COMMON_QUERY_PARAMS = [
23
23
  :format, # Search, Cat, ...
24
24
  :pretty, # Pretty-print the response
25
- :human # Return numeric values in human readable format
25
+ :human, # Return numeric values in human readable format
26
+ :filter_path # Filter the JSON response
26
27
  ]
27
28
 
28
29
  HTTP_GET = 'GET'.freeze
@@ -47,7 +47,7 @@ module Elasticsearch
47
47
  path = "_cat/nodes"
48
48
 
49
49
  params = Utils.__validate_and_extract_params arguments, valid_params
50
- params[:h] = Utils.__listify(params[:h]) if params[:h]
50
+ params[:h] = Utils.__listify(params[:h], :escape => false) if params[:h]
51
51
 
52
52
  body = nil
53
53
 
@@ -0,0 +1,31 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # @option arguments [List] :index A comma-separated list of index names; use `_all` or empty string for all indices
7
+ # @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
8
+ # @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
9
+ # @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, none, all)
10
+ #
11
+ # @see http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html
12
+ #
13
+ def flush_synced(arguments={})
14
+ valid_params = [
15
+ ]
16
+ method = HTTP_POST
17
+ path = Utils.__pathify Utils.__listify(arguments[:index]), '_flush/synced'
18
+
19
+ params = Utils.__validate_and_extract_params arguments, valid_params
20
+ body = nil
21
+
22
+ if Array(arguments[:ignore]).include?(404)
23
+ Utils.__rescue_from_not_found { perform_request(method, path, params, body).body }
24
+ else
25
+ perform_request(method, path, params, body).body
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -76,6 +76,8 @@ module Elasticsearch
76
76
  # @option arguments [Boolean] :explain Specify whether to return detailed information about score computation
77
77
  # as part of a hit
78
78
  # @option arguments [List] :fields A comma-separated list of fields to return as part of a hit
79
+ # @option arguments [List] :fielddata_fields A comma-separated list of fields to return as the field data
80
+ # representation of a field for each hit
79
81
  # @option arguments [Number] :from Starting offset (default: 0)
80
82
  # @option arguments [String] :ignore_indices When performed on multiple indices, allows to ignore `missing` ones
81
83
  # (options: none, missing)
@@ -120,6 +122,7 @@ module Elasticsearch
120
122
  :default_operator,
121
123
  :df,
122
124
  :explain,
125
+ :fielddata_fields,
123
126
  :fields,
124
127
  :from,
125
128
  :ignore_indices,
@@ -152,9 +155,14 @@ module Elasticsearch
152
155
  path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), UNDERSCORE_SEARCH )
153
156
 
154
157
  params = Utils.__validate_and_extract_params arguments, valid_params
158
+
155
159
  body = arguments[:body]
156
160
 
157
161
  params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
162
+ params[:fielddata_fields] = Utils.__listify(params[:fielddata_fields]) if params[:fielddata_fields]
163
+
164
+ # FIX: Unescape the `filter_path` parameter due to __listify default behavior. Investigate.
165
+ params[:filter_path] = defined?(EscapeUtils) ? EscapeUtils.unescape_url(params[:filter_path]) : CGI.unescape(params[:filter_path]) if params[:filter_path]
158
166
 
159
167
  perform_request(method, path, params, body).body
160
168
  end
@@ -28,13 +28,18 @@ module Elasticsearch
28
28
  # @example Escape values
29
29
  # __listify('foo','bar^bam') # => 'foo,bar%5Ebam'
30
30
  #
31
+ # @example Do not escape the values
32
+ # __listify('foo','bar^bam', escape: false) # => 'foo,bar^bam'
33
+ #
31
34
  # @api private
32
35
  def __listify(*list)
36
+ options = list.last.is_a?(Hash) ? list.pop : {}
37
+
33
38
  Array(list).flatten.
34
39
  map { |e| e.respond_to?(:split) ? e.split(',') : e }.
35
40
  flatten.
36
41
  compact.
37
- map { |e| __escape(e) }.
42
+ map { |e| options[:escape] == false ? e : __escape(e) }.
38
43
  join(',')
39
44
  end
40
45
 
@@ -133,7 +138,7 @@ module Elasticsearch
133
138
  arguments
134
139
  else
135
140
  __validate_params(arguments, params)
136
- __extract_params(arguments, params)
141
+ __extract_params(arguments, params, options.merge(:escape => false))
137
142
  end
138
143
  end
139
144
 
@@ -144,10 +149,10 @@ module Elasticsearch
144
149
  end
145
150
  end
146
151
 
147
- def __extract_params(arguments, params=[])
152
+ def __extract_params(arguments, params=[], options={})
148
153
  result = arguments.select { |k,v| COMMON_QUERY_PARAMS.include?(k) || params.include?(k) }
149
154
  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
155
+ result = Hash[result.map { |k,v| v.is_a?(Array) ? [k, __listify(v, options)] : [k,v] }] # Listify Arrays
151
156
  result
152
157
  end
153
158
 
@@ -168,9 +173,6 @@ module Elasticsearch
168
173
  # @api private
169
174
  #
170
175
  def __extract_parts(arguments, valid_parts=[])
171
- # require 'pry'; binding.pry;
172
- # parts = arguments.keys.select { |a| valid_parts.include?(a) }.map { |a| a.to_s }.sort
173
-
174
176
  parts = Hash[arguments.select { |k,v| valid_parts.include?(k) }]
175
177
  parts = parts.reduce([]) { |sum, item| k, v = item; v.is_a?(TrueClass) ? sum << k.to_s : sum << v }
176
178
 
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module API
3
- VERSION = "1.0.12"
3
+ VERSION = "1.0.13"
4
4
  end
5
5
  end
@@ -23,12 +23,14 @@ Turn.config.format = :pretty
23
23
 
24
24
  # Launch test cluster
25
25
  #
26
- Elasticsearch::Extensions::Test::Cluster.start(nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?
26
+ if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?
27
+ Elasticsearch::Extensions::Test::Cluster.start(nodes: 1, es_params: "-D es.repositories.url.allowed_urls=http://snapshot.test*")
28
+ end
27
29
 
28
30
  # Register `at_exit` handler for server shutdown.
29
31
  # MUST be called before requiring `test/unit`.
30
32
  #
31
- at_exit { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] }
33
+ at_exit { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] and Elasticsearch::Extensions::Test::Cluster.running? }
32
34
 
33
35
  class String
34
36
  # Reset the `ansi` method on CI
@@ -128,6 +130,7 @@ end
128
130
 
129
131
  module Elasticsearch
130
132
  module YamlTestSuite
133
+ $last_response = ''
131
134
  $results = {}
132
135
  $stash = {}
133
136
 
@@ -180,7 +183,7 @@ module Elasticsearch
180
183
 
181
184
  $stderr.puts "ARGUMENTS: #{arguments.inspect}" if ENV['DEBUG']
182
185
 
183
- $results[test.hash] = namespace.reduce($client) do |memo, current|
186
+ $last_response = namespace.reduce($client) do |memo, current|
184
187
  unless current == namespace.last
185
188
  memo = memo.send(current)
186
189
  else
@@ -188,12 +191,18 @@ module Elasticsearch
188
191
  end
189
192
  memo
190
193
  end
194
+
195
+ $results[test.hash] = $last_response
191
196
  end
192
197
 
193
- def evaluate(test, property)
194
- property.gsub(/\\\./, '_____').split('.').reduce($results[test.hash]) do |memo, attr|
198
+ def evaluate(test, property, response=nil)
199
+ response ||= $results[test.hash]
200
+ property.gsub(/\\\./, '_____').split('.').reduce(response) do |memo, attr|
195
201
  if memo
196
- attr = attr.gsub(/_____/, '.') if attr
202
+ if attr
203
+ attr = attr.gsub(/_____/, '.')
204
+ attr = $stash[attr] if attr.start_with? '$'
205
+ end
197
206
  memo = memo.is_a?(Hash) ? memo[attr] : memo[attr.to_i]
198
207
  end
199
208
  memo
@@ -322,10 +331,18 @@ suites.each do |suite|
322
331
  # --- Register test setup -------------------------------------------
323
332
  setup do
324
333
  actions.select { |a| a['setup'] }.first['setup'].each do |action|
325
- next unless action['do']
326
- api, arguments = action['do'].to_a.first
327
- arguments = Utils.symbolize_keys(arguments)
328
- Runner.perform_api_call((test.to_s + '___setup'), api, arguments)
334
+ if action['do']
335
+ api, arguments = action['do'].to_a.first
336
+ arguments = Utils.symbolize_keys(arguments)
337
+ Runner.perform_api_call((test.to_s + '___setup'), api, arguments)
338
+ end
339
+ if action['set']
340
+ stash = action['set']
341
+ property, variable = stash.to_a.first
342
+ result = Runner.evaluate(test, property, $last_response)
343
+ $stderr.puts "STASH: '$#{variable}' => #{result.inspect}" if ENV['DEBUG']
344
+ Runner.set variable, result
345
+ end
329
346
  end
330
347
  end
331
348
 
@@ -386,8 +403,10 @@ suites.each do |suite|
386
403
 
387
404
  when property = action['is_false']
388
405
  result = Runner.evaluate(test, property)
389
- $stderr.puts "CHECK: Expected '#{property}' to be false, is: #{result.inspect}" if ENV['DEBUG']
390
- assert( !!! result, "Property '#{property}' should be false, is: #{result.inspect}")
406
+ $stderr.puts "CHECK: Expected '#{property}' to be nil, false, 0 or empty string, is: #{result.inspect}" if ENV['DEBUG']
407
+ assert_block "Property '#{property}' should be nil, false, 0 or empty string, but is: #{result.inspect}" do
408
+ result.nil? || result == false || result == 0 || result == ''
409
+ end
391
410
 
392
411
  when a = action['match']
393
412
  property, value = a.to_a.first
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class IndicesFlushSyncedTest < ::Test::Unit::TestCase
6
+
7
+ context "Indices: Flush synced" 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 'foo/_flush/synced', url
14
+ assert_equal Hash.new, params
15
+ assert_nil body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.indices.flush_synced :index => 'foo'
20
+ end
21
+
22
+ should "raise a NotFound exception" do
23
+ subject.expects(:perform_request).raises(NotFound)
24
+
25
+ assert_raise NotFound do
26
+ subject.indices.flush_synced :index => 'foo'
27
+ end
28
+ end
29
+
30
+ should "catch a NotFound exception with the ignore parameter" do
31
+ subject.expects(:perform_request).raises(NotFound)
32
+
33
+ assert_nothing_raised do
34
+ subject.indices.flush_synced :index => 'foo', :ignore => 404
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -61,6 +61,10 @@ module Elasticsearch
61
61
  assert_equal 'foo,bar%5Ebam', __listify(['foo', 'bar^bam'])
62
62
  end
63
63
 
64
+ should "not encode special characters when the :escape option is set" do
65
+ assert_equal 'foo,bar^bam', __listify(['foo', 'bar^bam'], :escape => false)
66
+ end
67
+
64
68
  end
65
69
 
66
70
  context "__pathify" do
@@ -186,6 +190,11 @@ module Elasticsearch
186
190
  result = __validate_and_extract_params( { :foo => ['a', 'b'] }, [:foo] )
187
191
  assert_equal( { :foo => 'a,b'}, result )
188
192
  end
193
+
194
+ should "not escape the parameters" do
195
+ result = __validate_and_extract_params( { :foo => ['a.*', 'b.*'] }, [:foo] )
196
+ assert_equal( { :foo => 'a.*,b.*'}, result )
197
+ end
189
198
  end
190
199
 
191
200
  context "__extract_parts" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-02 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -404,6 +404,7 @@ files:
404
404
  - lib/elasticsearch/api/actions/indices/exists_template.rb
405
405
  - lib/elasticsearch/api/actions/indices/exists_type.rb
406
406
  - lib/elasticsearch/api/actions/indices/flush.rb
407
+ - lib/elasticsearch/api/actions/indices/flush_synced.rb
407
408
  - lib/elasticsearch/api/actions/indices/get.rb
408
409
  - lib/elasticsearch/api/actions/indices/get_alias.rb
409
410
  - lib/elasticsearch/api/actions/indices/get_aliases.rb
@@ -527,6 +528,7 @@ files:
527
528
  - test/unit/indices/exists_template_test.rb
528
529
  - test/unit/indices/exists_test.rb
529
530
  - test/unit/indices/exists_type_test.rb
531
+ - test/unit/indices/flush_synced_test.rb
530
532
  - test/unit/indices/flush_test.rb
531
533
  - test/unit/indices/get_alias_test.rb
532
534
  - test/unit/indices/get_aliases_test.rb
@@ -679,6 +681,7 @@ test_files:
679
681
  - test/unit/indices/exists_template_test.rb
680
682
  - test/unit/indices/exists_test.rb
681
683
  - test/unit/indices/exists_type_test.rb
684
+ - test/unit/indices/flush_synced_test.rb
682
685
  - test/unit/indices/flush_test.rb
683
686
  - test/unit/indices/get_alias_test.rb
684
687
  - test/unit/indices/get_aliases_test.rb