elasticsearch-api 1.0.15 → 1.0.16.pre

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: 68336ac9575020a4a102cbde2a0157d6f47c6b67
4
- data.tar.gz: 50c1630f17dec457ff7068c78d48acfd8884ab2e
3
+ metadata.gz: 081fe135d7cd87037475fd790752c46d26b170ed
4
+ data.tar.gz: 3d8753842bdfff64dffcccd95e431988b0cf943a
5
5
  SHA512:
6
- metadata.gz: 24d082a7abe1d6a40f9051d4d849d57e4e0efaec7e891a38e237ccc0f6b35ce9c3b606490d14636fdcf483e18bcfe097a75a5bcb1b5e6b96efe79ae809bd7e4a
7
- data.tar.gz: 5129cac0908e6f23afe58723a2a6ea6e4cc4d087a5525060b6e6cb028f5d41706336e4d96fec1142684f4fa8f25894864681718b59ca26223fc0c6ce9b787069
6
+ metadata.gz: 90ae2bede4146274cf1bcbae9477999e7144982d595ec67e64bf1839337ebfa93083ed9afac814cf2f0746de40eab462a973a0bebb7d55e4919d78795eeed9bb
7
+ data.tar.gz: 22646e3f5530a92e0e25d380bfcef7ccd6db6e8b06dd1048a83fb1eaf3912a0581de5607701511f156422003dad597fc28ede8b90c6324440201bac9fc675be8
data/Gemfile CHANGED
@@ -3,14 +3,14 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in elasticsearch-api.gemspec
4
4
  gemspec
5
5
 
6
- if File.exists? File.expand_path("../../elasticsearch/elasticsearch.gemspec", __FILE__)
6
+ if File.exist? File.expand_path("../../elasticsearch/elasticsearch.gemspec", __FILE__)
7
7
  gem 'elasticsearch', :path => File.expand_path("../../elasticsearch", __FILE__), :require => false
8
8
  end
9
9
 
10
- if File.exists? File.expand_path("../../elasticsearch-transport", __FILE__)
10
+ if File.exist? File.expand_path("../../elasticsearch-transport", __FILE__)
11
11
  gem 'elasticsearch-transport', :path => File.expand_path("../../elasticsearch-transport", __FILE__), :require => true
12
12
  end
13
13
 
14
- if File.exists? File.expand_path("../../elasticsearch-extensions", __FILE__)
14
+ if File.exist? File.expand_path("../../elasticsearch-extensions", __FILE__)
15
15
  gem 'elasticsearch-extensions', :path => File.expand_path("../../elasticsearch-extensions", __FILE__), :require => false
16
16
  end
data/README.md CHANGED
@@ -14,9 +14,9 @@ library.
14
14
 
15
15
  The library is compatible with Ruby 1.8.7 or higher.
16
16
 
17
- The library is compatible with Elasticsearch 0.90 and 1.0 -- you have to install and use a matching version, though.
17
+ The library is compatible with Elasticsearch 0.90, 1.x and 2.x -- you have to install and use a matching version, though.
18
18
 
19
- The 1.x versions and the master branch are compatible with **Elasticsearch 1.x** API.
19
+ The 1.x versions and the master branch are compatible with Elasticsearch 1.x and 2.x APIs.
20
20
 
21
21
  To use the **Elasticsearch 0.90** API, install the **0.4.x** gem version or use the corresponding
22
22
  [`0.4`](https://github.com/elasticsearch/elasticsearch-ruby/tree/0.4) branch.
@@ -155,6 +155,18 @@ mash.aggregations.tags.terms.first
155
155
  # => #<Hashie::Mash count=3 term="z">
156
156
  ```
157
157
 
158
+ ### Using a Custom JSON Serializer
159
+
160
+ The library uses the [MultiJson](https://rubygems.org/gems/multi_json/) gem by default,
161
+ but allows you to set a custom JSON library, provided it uses the standard `load/dump`
162
+ interface:
163
+
164
+ ```ruby
165
+ Elasticsearch::API.settings[:serializer] = JrJackson::Json
166
+ Elasticsearch::API.serializer.dump({foo: 'bar'})
167
+ # => {"foo":"bar"}
168
+ ```
169
+
158
170
  ## Development
159
171
 
160
172
  To work on the code, clone and bootstrap the main repository first --
data/Rakefile CHANGED
@@ -71,7 +71,7 @@ namespace :test do
71
71
  es_version_info = client.info['version']
72
72
  build_hash = es_version_info['build_hash']
73
73
  cluster_running = true
74
- rescue Faraday::Error::ConnectionFailed => e
74
+ rescue Faraday::Error::ConnectionFailed
75
75
  STDERR.puts "[!] Test cluster not running?"
76
76
  cluster_running = false
77
77
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency "multi_json"
24
24
 
25
25
  s.add_development_dependency "bundler", "> 1"
26
- s.add_development_dependency "rake"
26
+ s.add_development_dependency "rake", "< 11.0"
27
27
 
28
28
  s.add_development_dependency "elasticsearch"
29
29
  s.add_development_dependency "elasticsearch-transport"
@@ -10,6 +10,8 @@ Dir[ File.expand_path('../api/namespace/**/*.rb', __FILE__) ].each { |f| require
10
10
 
11
11
  module Elasticsearch
12
12
  module API
13
+ DEFAULT_SERIALIZER = MultiJson
14
+
13
15
  COMMON_PARAMS = [
14
16
  :ignore, # Client specific parameters
15
17
  :index, :type, :id, # :index/:type/:id
@@ -47,15 +49,16 @@ module Elasticsearch
47
49
  Elasticsearch::API::Cat
48
50
  end
49
51
 
50
- module ClassMethods
51
-
52
- # Access the module settings
53
- #
54
- def settings
55
- @settings ||= {}
56
- end
52
+ # The serializer class
53
+ #
54
+ def self.serializer
55
+ settings[:serializer] || DEFAULT_SERIALIZER
57
56
  end
58
57
 
59
- extend ClassMethods
58
+ # Access the module settings
59
+ #
60
+ def self.settings
61
+ @settings ||= {}
62
+ end
60
63
  end
61
64
  end
@@ -4,8 +4,9 @@ module Elasticsearch
4
4
 
5
5
  # Perform multiple index, delete or update operations in a single request.
6
6
  #
7
- # Pass the operations in the `:body` option as an array of hashes, following Elasticsearch conventions.
8
- # For operations which take data, pass them as the `:data` option in the operation hash.
7
+ # Supports various different formats of the payload: Array of Strings, Header/Data pairs,
8
+ # or the conveniency "combined" format where data is passed along with the header
9
+ # in a single item in a custom `:data` key.
9
10
  #
10
11
  # @example Perform three operations in a single request, passing actions and data as an array of hashes
11
12
  #
@@ -0,0 +1,40 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Cat
4
+ module Actions
5
+
6
+ # Shows all repositories registered in a cluster
7
+ #
8
+ # @example Return list of repositories
9
+ #
10
+ # client.cat.repositories
11
+ #
12
+ # @example Return only id for each repository
13
+ #
14
+ # client.cat.repositories h: 'id'
15
+ #
16
+ # @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
17
+ # @option arguments [List] :h Comma-separated list of column names to display
18
+ # @option arguments [Boolean] :help Return help information
19
+ # @option arguments [Boolean] :v Verbose mode. Display column headers
20
+ #
21
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-repositories.html
22
+ #
23
+ def repositories(arguments={})
24
+ valid_params = [
25
+ :master_timeout,
26
+ :h,
27
+ :help,
28
+ :v ]
29
+
30
+ method = HTTP_GET
31
+ path = "_cat/repositories"
32
+ params = Utils.__validate_and_extract_params arguments, valid_params
33
+ body = nil
34
+
35
+ perform_request(method, path, params, body).body
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,45 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Cat
4
+ module Actions
5
+
6
+ # Shows all snapshots that belong to a specific repository
7
+ #
8
+ # @example Return snapshots for 'my_repository'
9
+ #
10
+ # client.cat.snapshots repository: 'my_repository'
11
+ #
12
+ # @example Return id, status and start_epoch for 'my_repository'
13
+ #
14
+ # client.cat.snapshots repository: 'my_repository', h: 'id,status,start_epoch'
15
+ #
16
+ # @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
17
+ # @option arguments [List] :h Comma-separated list of column names to display
18
+ # @option arguments [Boolean] :help Return help information
19
+ # @option arguments [Boolean] :v Verbose mode. Display column headers
20
+ #
21
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-snapshots.html
22
+ #
23
+ def snapshots(arguments={})
24
+ raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
25
+
26
+ valid_params = [
27
+ :master_timeout,
28
+ :h,
29
+ :help,
30
+ :v ]
31
+
32
+ repository = arguments.delete(:repository)
33
+
34
+ method = HTTP_GET
35
+ path = Utils.__pathify "_cat/snapshots", Utils.__escape(repository)
36
+ params = Utils.__validate_and_extract_params arguments, valid_params
37
+ body = nil
38
+
39
+ perform_request(method, path, params, body).body
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,62 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # Force merge an index, list of indices, or all indices in the cluster.
7
+ #
8
+ # @example Fully force merge an index
9
+ #
10
+ # client.indices.forcemerge index: 'foo', max_num_segments: 1
11
+ #
12
+ # @example Do not flush index after force-merging
13
+ #
14
+ # client.indices.forcemerge index: 'foo', flush: false
15
+ #
16
+ # @example Do not expunge deleted documents after force-merging
17
+ #
18
+ # client.indices.forcemerge index: 'foo', only_expunge_deletes: false
19
+ #
20
+ # @example Force merge a list of indices
21
+ #
22
+ # client.indices.forcemerge index: ['foo', 'bar']
23
+ # client.indices.forcemerge index: 'foo,bar'
24
+ #
25
+ # @example forcemerge a list of indices matching wildcard expression
26
+ #
27
+ # client.indices.forcemerge index: 'foo*'
28
+ #
29
+ # @example forcemerge all indices
30
+ #
31
+ # client.indices.forcemerge index: '_all'
32
+ #
33
+ # @option arguments [List] :index A comma-separated list of indices to forcemerge;
34
+ # use `_all` to forcemerge all indices
35
+ # @option arguments [Number] :max_num_segments The number of segments the index should be merged into
36
+ # (default: dynamic)
37
+ # @option arguments [Boolean] :only_expunge_deletes Specify whether the operation should only expunge
38
+ # deleted documents
39
+ # @option arguments [Boolean] :flush Specify whether the index should be flushed after performing the operation
40
+ # (default: true)
41
+ #
42
+ # @see http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html
43
+ #
44
+ def forcemerge(arguments={})
45
+ valid_params = [
46
+ :max_num_segments,
47
+ :only_expunge_deletes,
48
+ :flush
49
+ ]
50
+
51
+ method = HTTP_POST
52
+ path = Utils.__pathify Utils.__listify(arguments[:index]), '_forcemerge'
53
+
54
+ params = Utils.__validate_and_extract_params arguments, valid_params
55
+ body = nil
56
+
57
+ perform_request(method, path, params, body).body
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -8,6 +8,8 @@ module Elasticsearch
8
8
  # The "optimize" operation merges the index segments, increasing search performance.
9
9
  # It corresponds to a Lucene "merge" operation.
10
10
  #
11
+ # @deprecated The "optimize" action has been deprecated in favor of forcemerge [https://github.com/elastic/elasticsearch/pull/13778]
12
+ #
11
13
  # @example Fully optimize an index (merge to one segment)
12
14
  #
13
15
  # client.indices.optimize index: 'foo', max_num_segments: 1, wait_for_merge: false
@@ -34,7 +34,8 @@ module Elasticsearch
34
34
  valid_params = [
35
35
  :ignore_unavailable,
36
36
  :allow_no_indices,
37
- :expand_wildcards ]
37
+ :expand_wildcards,
38
+ :percolate_format ]
38
39
 
39
40
  method = HTTP_GET
40
41
  path = "_mpercolate"
@@ -44,7 +45,7 @@ module Elasticsearch
44
45
 
45
46
  case
46
47
  when body.is_a?(Array)
47
- payload = body.map { |d| d.is_a?(String) ? d : MultiJson.dump(d) }
48
+ payload = body.map { |d| d.is_a?(String) ? d : Elasticsearch::API.serializer.dump(d) }
48
49
  payload << "" unless payload.empty?
49
50
  payload = payload.join("\n")
50
51
  else
@@ -56,11 +56,11 @@ module Elasticsearch
56
56
  sum << data
57
57
  sum
58
58
  end.
59
- map { |item| MultiJson.dump(item) }
59
+ map { |item| Elasticsearch::API.serializer.dump(item) }
60
60
  payload << "" unless payload.empty?
61
61
  payload = payload.join("\n")
62
62
  when body.is_a?(Array)
63
- payload = body.map { |d| d.is_a?(String) ? d : MultiJson.dump(d) }
63
+ payload = body.map { |d| d.is_a?(String) ? d : Elasticsearch::API.serializer.dump(d) }
64
64
  payload << "" unless payload.empty?
65
65
  payload = payload.join("\n")
66
66
  else
@@ -158,8 +158,8 @@ module Elasticsearch
158
158
 
159
159
  body = arguments[:body]
160
160
 
161
- params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
162
- params[:fielddata_fields] = Utils.__listify(params[:fielddata_fields]) if params[:fielddata_fields]
161
+ params[:fields] = Utils.__listify(params[:fields], :escape => false) if params[:fields]
162
+ params[:fielddata_fields] = Utils.__listify(params[:fielddata_fields], :escape => false) if params[:fielddata_fields]
163
163
 
164
164
  # FIX: Unescape the `filter_path` parameter due to __listify default behavior. Investigate.
165
165
  params[:filter_path] = defined?(EscapeUtils) ? EscapeUtils.unescape_url(params[:filter_path]) : CGI.unescape(params[:filter_path]) if params[:filter_path]
@@ -65,6 +65,10 @@ module Elasticsearch
65
65
 
66
66
  # Convert an array of payloads into Elasticsearch `header\ndata` format
67
67
  #
68
+ # Supports various different formats of the payload: Array of Strings, Header/Data pairs,
69
+ # or the conveniency "combined" format where data is passed along with the header
70
+ # in a single item.
71
+ #
68
72
  # Elasticsearch::API::Utils.__bulkify [
69
73
  # { :index => { :_index => 'myindexA', :_type => 'mytype', :_id => '1', :data => { :title => 'Test' } } },
70
74
  # { :update => { :_index => 'myindexB', :_type => 'mytype', :_id => '2', :data => { :doc => { :title => 'Update' } } } }
@@ -76,22 +80,24 @@ module Elasticsearch
76
80
  # # => {"doc":{"title":"Update"}}
77
81
  #
78
82
  def __bulkify(payload)
83
+ operations = %w[index create delete update]
84
+
79
85
  case
86
+
80
87
  # Hashes with `:data`
81
- when payload.any? { |d| d.is_a?(Hash) && d.values.first.is_a?(Hash) && (d.values.first[:data] || d.values.first['data']) }
88
+ when payload.any? { |d| d.is_a?(Hash) && d.values.first.is_a?(Hash) && operations.include?(d.keys.first.to_s) && (d.values.first[:data] || d.values.first['data']) }
82
89
  payload = payload.
83
- inject([]) do |sum, item|
84
- operation, meta = item.to_a.first
85
- meta = meta.clone
86
- data = meta.delete(:data) || meta.delete('data')
87
-
88
- sum << { operation => meta }
89
- sum << data if data
90
- sum
91
- end.
92
- map { |item| MultiJson.dump(item) }
93
- payload << "" unless payload.empty?
94
- return payload.join("\n")
90
+ inject([]) do |sum, item|
91
+ operation, meta = item.to_a.first
92
+ meta = meta.clone
93
+ data = meta.delete(:data) || meta.delete('data')
94
+
95
+ sum << { operation => meta }
96
+ sum << data if data
97
+ sum
98
+ end.
99
+ map { |item| Elasticsearch::API.serializer.dump(item) }
100
+ payload << '' unless payload.empty?
95
101
 
96
102
  # Array of strings
97
103
  when payload.all? { |d| d.is_a? String }
@@ -99,7 +105,7 @@ module Elasticsearch
99
105
 
100
106
  # Header/Data pairs
101
107
  else
102
- payload = payload.map { |item| MultiJson.dump(item) }
108
+ payload = payload.map { |item| Elasticsearch::API.serializer.dump(item) }
103
109
  payload << ''
104
110
  end
105
111
 
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module API
3
- VERSION = "1.0.15"
3
+ VERSION = "1.0.16.pre"
4
4
  end
5
5
  end
@@ -293,8 +293,15 @@ suites.each do |suite|
293
293
  $client.indices.delete_template name: '*'
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
+ $client.snapshot.delete repository: 'test_cat_snapshots_1', snapshot: 'snap1', ignore: 404
297
+ $client.snapshot.delete repository: 'test_cat_snapshots_1', snapshot: 'snap2', ignore: 404
296
298
  $client.snapshot.delete_repository repository: 'test_repo_create_1', ignore: 404
297
299
  $client.snapshot.delete_repository repository: 'test_repo_restore_1', ignore: 404
300
+ $client.snapshot.delete_repository repository: 'test_repo_get_1', ignore: 404
301
+ $client.snapshot.delete_repository repository: 'test_repo_get_2', ignore: 404
302
+ $client.snapshot.delete_repository repository: 'test_cat_repo_1', ignore: 404
303
+ $client.snapshot.delete_repository repository: 'test_cat_repo_2', ignore: 404
304
+ $client.snapshot.delete_repository repository: 'test_cat_snapshots_1', ignore: 404
298
305
  # FIXME: This shouldn't be needed -------------
299
306
  FileUtils.rm_rf('/tmp/test_repo_create_1_loc')
300
307
  FileUtils.rm_rf('/tmp/test_repo_restore_1_loc')
@@ -17,6 +17,10 @@ module Elasticsearch
17
17
  assert_equal 'bar', Elasticsearch::API.settings[:foo]
18
18
  end
19
19
 
20
+ should "have default serializer" do
21
+ assert_equal MultiJson, Elasticsearch::API.serializer
22
+ end
23
+
20
24
  end
21
25
 
22
26
  end
@@ -16,7 +16,7 @@ module Elasticsearch
16
16
  if RUBY_1_8
17
17
  lines = body.split("\n")
18
18
 
19
- assert_equal 5, lines.size
19
+ assert_equal 7, lines.size
20
20
  assert_match /\{"index"\:\{/, lines[0]
21
21
  assert_match /\{"title"\:"Test"/, lines[1]
22
22
  assert_match /\{"update"\:\{/, lines[2]
@@ -28,6 +28,8 @@ module Elasticsearch
28
28
  {"update":{"_index":"myindexB","_type":"mytype","_id":"2"}}
29
29
  {"doc":{"title":"Update"}}
30
30
  {"delete":{"_index":"myindexC","_type":"mytypeC","_id":"3"}}
31
+ {"index":{"_index":"myindexD","_type":"mytype","_id":"1"}}
32
+ {"data":"MYDATA"}
31
33
  PAYLOAD
32
34
  end
33
35
  true
@@ -36,7 +38,8 @@ module Elasticsearch
36
38
  subject.bulk :body => [
37
39
  { :index => { :_index => 'myindexA', :_type => 'mytype', :_id => '1', :data => { :title => 'Test' } } },
38
40
  { :update => { :_index => 'myindexB', :_type => 'mytype', :_id => '2', :data => { :doc => { :title => 'Update' } } } },
39
- { :delete => { :_index => 'myindexC', :_type => 'mytypeC', :_id => '3' } }
41
+ { :delete => { :_index => 'myindexC', :_type => 'mytypeC', :_id => '3' } },
42
+ { :index => { :_index => 'myindexD', :_type => 'mytype', :_id => '1', :data => { :data => 'MYDATA' } } },
40
43
  ]
41
44
  end
42
45
 
@@ -50,6 +53,32 @@ module Elasticsearch
50
53
  subject.bulk :index => 'myindex', :body => []
51
54
  end
52
55
 
56
+ should "handle `:data` keys correctly in header/data payloads" do
57
+ subject.expects(:perform_request).with do |method, url, params, body|
58
+ lines = body.split("\n")
59
+ assert_equal 2, lines.size
60
+
61
+ header = MultiJson.load(lines.first)
62
+ data = MultiJson.load(lines.last)
63
+
64
+ assert_equal 'myindex', header['update']['_index']
65
+ assert_equal 'mytype', header['update']['_type']
66
+ assert_equal '1', header['update']['_id']
67
+
68
+ assert_equal({'data' => { 'title' => 'Update' }}, data['doc'])
69
+ # assert_equal <<-PAYLOAD.gsub(/^\s+/, ''), body
70
+ # {"update":{"_index":"myindex","_type":"mytype","_id":"1"}}
71
+ # {"doc":{"data":{"title":"Update"}}}
72
+ # PAYLOAD
73
+ true
74
+ end.returns(FakeResponse.new)
75
+
76
+ subject.bulk :body => [
77
+ { :update => { :_index => 'myindex', :_type => 'mytype', :_id => '1' } },
78
+ { :doc => { :data => { :title => 'Update' } } }
79
+ ]
80
+ end
81
+
53
82
  should "post a string payload" do
54
83
  subject.expects(:perform_request).with do |method, url, params, body|
55
84
  assert_equal "foo\nbar", body
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class CatRepositoriesTest < ::Test::Unit::TestCase
6
+
7
+ context "Cat: Repositories" 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/repositories', url
14
+ assert_equal Hash.new, params
15
+ assert_nil body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.cat.repositories
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 CatSnapshotsTest < ::Test::Unit::TestCase
6
+
7
+ context "Cat: Snapshots" 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/snapshots/foo', url
14
+ assert_equal Hash.new, params
15
+ assert_nil body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.cat.snapshots :repository => 'foo'
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 IndicesForcemergeTest < ::Test::Unit::TestCase
6
+
7
+ context "Indices: Forcemerge" 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 '_forcemerge', url
14
+ assert_equal Hash.new, params
15
+ assert_nil body
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.indices.forcemerge
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -101,6 +101,14 @@ module Elasticsearch
101
101
  subject.search :index => 'foo^bar', :type => 'bar/bam'
102
102
  end
103
103
 
104
+ should "not URL-escape the fields parameters" do
105
+ subject.expects(:perform_request).with do |method, url, params, body|
106
+ assert_equal 'foo^bar', params[:fields]
107
+ true
108
+ end.returns(FakeResponse.new)
109
+
110
+ subject.search :index => 'foo', :type => 'bar', :fields => 'foo^bar'
111
+ end
104
112
  end
105
113
 
106
114
  end
@@ -132,8 +132,8 @@ module Elasticsearch
132
132
  PAYLOAD
133
133
  end
134
134
 
135
- should "not modify the original payload" do
136
- original = [ { :index => {:foo => 'bar', :data => { :moo => 'bam' }} } ]
135
+ should "not modify the original payload with the data option" do
136
+ original = [ { :index => {:foo => 'bar', :data => {:moo => 'bam'} } } ]
137
137
  result = Elasticsearch::API::Utils.__bulkify original
138
138
  assert_not_nil original.first[:index][:data], "Deleted :data from #{original}"
139
139
  assert_equal <<-PAYLOAD.gsub(/^\s+/, ''), result
@@ -142,6 +142,23 @@ module Elasticsearch
142
142
  PAYLOAD
143
143
  end
144
144
 
145
+ should "not modify the original payload with meta/data pairs" do
146
+ original = [ { :index => {:foo => 'bar'} }, { :data => {:a => 'b', :data => {:c => 'd'} } } ]
147
+ result = Elasticsearch::API::Utils.__bulkify original
148
+
149
+ assert_not_nil original.last[:data], "Deleted :data from #{original}"
150
+ assert_not_nil original.last[:data][:data], "Deleted :data from #{original}"
151
+
152
+ lines = result.split("\n")
153
+ assert_equal 2, lines.size
154
+
155
+ header = MultiJson.load(lines.first)
156
+ data = MultiJson.load(lines.last)
157
+
158
+ assert_equal 'bar', header['index']['foo']
159
+ assert_equal 'b', data['data']['a']
160
+ assert_equal 'd', data['data']['data']['c']
161
+ end
145
162
  end
146
163
 
147
164
  context "__validate_and_extract_params" 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.15
4
+ version: 1.0.16.pre
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-12-04 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "<"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '11.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '11.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: elasticsearch
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -366,8 +366,10 @@ files:
366
366
  - lib/elasticsearch/api/actions/cat/pending_tasks.rb
367
367
  - lib/elasticsearch/api/actions/cat/plugins.rb
368
368
  - lib/elasticsearch/api/actions/cat/recovery.rb
369
+ - lib/elasticsearch/api/actions/cat/repositories.rb
369
370
  - lib/elasticsearch/api/actions/cat/segments.rb
370
371
  - lib/elasticsearch/api/actions/cat/shards.rb
372
+ - lib/elasticsearch/api/actions/cat/snapshots.rb
371
373
  - lib/elasticsearch/api/actions/cat/thread_pool.rb
372
374
  - lib/elasticsearch/api/actions/clear_scroll.rb
373
375
  - lib/elasticsearch/api/actions/cluster/get_settings.rb
@@ -406,6 +408,7 @@ files:
406
408
  - lib/elasticsearch/api/actions/indices/exists_type.rb
407
409
  - lib/elasticsearch/api/actions/indices/flush.rb
408
410
  - lib/elasticsearch/api/actions/indices/flush_synced.rb
411
+ - lib/elasticsearch/api/actions/indices/forcemerge.rb
409
412
  - lib/elasticsearch/api/actions/indices/get.rb
410
413
  - lib/elasticsearch/api/actions/indices/get_alias.rb
411
414
  - lib/elasticsearch/api/actions/indices/get_aliases.rb
@@ -492,8 +495,10 @@ files:
492
495
  - test/unit/cat/pending_tasks_test.rb
493
496
  - test/unit/cat/plugins_test.rb
494
497
  - test/unit/cat/recovery_test.rb
498
+ - test/unit/cat/repositories_test.rb
495
499
  - test/unit/cat/segments_test.rb
496
500
  - test/unit/cat/shards_test.rb
501
+ - test/unit/cat/snapshots_test.rb
497
502
  - test/unit/cat/thread_pool_test.rb
498
503
  - test/unit/clear_scroll_test.rb
499
504
  - test/unit/client_test.rb
@@ -534,6 +539,7 @@ files:
534
539
  - test/unit/indices/exists_type_test.rb
535
540
  - test/unit/indices/flush_synced_test.rb
536
541
  - test/unit/indices/flush_test.rb
542
+ - test/unit/indices/forcemerge_test.rb
537
543
  - test/unit/indices/get_alias_test.rb
538
544
  - test/unit/indices/get_aliases_test.rb
539
545
  - test/unit/indices/get_field_mapping_test.rb
@@ -619,9 +625,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
619
625
  version: '0'
620
626
  required_rubygems_version: !ruby/object:Gem::Requirement
621
627
  requirements:
622
- - - ">="
628
+ - - ">"
623
629
  - !ruby/object:Gem::Version
624
- version: '0'
630
+ version: 1.3.1
625
631
  requirements: []
626
632
  rubyforge_project:
627
633
  rubygems_version: 2.2.2
@@ -648,8 +654,10 @@ test_files:
648
654
  - test/unit/cat/pending_tasks_test.rb
649
655
  - test/unit/cat/plugins_test.rb
650
656
  - test/unit/cat/recovery_test.rb
657
+ - test/unit/cat/repositories_test.rb
651
658
  - test/unit/cat/segments_test.rb
652
659
  - test/unit/cat/shards_test.rb
660
+ - test/unit/cat/snapshots_test.rb
653
661
  - test/unit/cat/thread_pool_test.rb
654
662
  - test/unit/clear_scroll_test.rb
655
663
  - test/unit/client_test.rb
@@ -690,6 +698,7 @@ test_files:
690
698
  - test/unit/indices/exists_type_test.rb
691
699
  - test/unit/indices/flush_synced_test.rb
692
700
  - test/unit/indices/flush_test.rb
701
+ - test/unit/indices/forcemerge_test.rb
693
702
  - test/unit/indices/get_alias_test.rb
694
703
  - test/unit/indices/get_aliases_test.rb
695
704
  - test/unit/indices/get_field_mapping_test.rb