elasticsearch-extensions 0.0.31 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # encoding: utf-8
2
19
 
3
20
  module Elasticsearch
@@ -23,10 +40,10 @@ module Elasticsearch
23
40
  end; extend self
24
41
 
25
42
  module API
26
- # Copy documents from one index into another and refresh the target index
43
+ # Copy documents from one index into another and refresh the destination index
27
44
  #
28
45
  # @example
29
- # client.reindex source: { index: 'test1' }, target: { index: 'test2' }, refresh: true
46
+ # client.reindex source: { index: 'test1' }, dest: { index: 'test2' }, refresh: true
30
47
  #
31
48
  # The method allows all the options as {Reindex::Reindex.new}.
32
49
  #
@@ -50,40 +67,40 @@ module Elasticsearch
50
67
  # client = Elasticsearch::Client.new
51
68
  # reindex = Elasticsearch::Extensions::Reindex.new \
52
69
  # source: { index: 'test1', client: client },
53
- # target: { index: 'test2' }
70
+ # dest: { index: 'test2' }
54
71
  #
55
72
  # reindex.perform
56
73
  #
57
74
  # @example Copy documents to a different cluster
58
75
  #
59
76
  # source_client = Elasticsearch::Client.new url: 'http://localhost:9200'
60
- # target_client = Elasticsearch::Client.new url: 'http://localhost:9250'
77
+ # destination_client = Elasticsearch::Client.new url: 'http://localhost:9250'
61
78
  #
62
79
  # reindex = Elasticsearch::Extensions::Reindex.new \
63
80
  # source: { index: 'test', client: source_client },
64
- # target: { index: 'test', client: target_client }
81
+ # dest: { index: 'test', client: destination_client }
65
82
  # reindex.perform
66
83
  #
67
84
  # @example Transform the documents during re-indexing
68
85
  #
69
86
  # reindex = Elasticsearch::Extensions::Reindex.new \
70
87
  # source: { index: 'test1', client: client },
71
- # target: { index: 'test2' },
88
+ # dest: { index: 'test2' },
72
89
  # transform: lambda { |doc| doc['_source']['category'].upcase! }
73
90
  #
74
91
  #
75
92
  # The reindexing process works by "scrolling" an index and sending
76
- # batches via the "Bulk" API to the target index/cluster
93
+ # batches via the "Bulk" API to the destination index/cluster
77
94
  #
78
95
  # @option arguments [String] :source The source index/cluster definition (*Required*)
79
- # @option arguments [String] :target The target index/cluster definition (*Required*)
96
+ # @option arguments [String] :dest The destination index/cluster definition (*Required*)
80
97
  # @option arguments [Proc] :transform A block which will be executed for each document
81
98
  # @option arguments [Integer] :batch_size The size of the batch for scroll operation (Default: 1000)
82
99
  # @option arguments [String] :scroll The timeout for the scroll operation (Default: 5min)
83
- # @option arguments [Boolean] :refresh Whether to refresh the target index after
100
+ # @option arguments [Boolean] :refresh Whether to refresh the destination index after
84
101
  # the operation is completed (Default: false)
85
102
  #
86
- # Be aware, that if you want to change the target index settings and/or mappings,
103
+ # Be aware, that if you want to change the destination index settings and/or mappings,
87
104
  # you have to do so in advance by using the "Indices Create" API.
88
105
  #
89
106
  # Note, that there is a native "Reindex" API in Elasticsearch 2.3.x and higer versions,
@@ -98,7 +115,7 @@ module Elasticsearch
98
115
  [
99
116
  [:source, :index],
100
117
  [:source, :client],
101
- [:target, :index]
118
+ [:dest, :index]
102
119
  ].each do |required_option|
103
120
  value = required_option.reduce(arguments) { |sum, o| sum = sum[o] ? sum[o] : {} }
104
121
 
@@ -113,7 +130,7 @@ module Elasticsearch
113
130
  refresh: false
114
131
  }.merge(arguments)
115
132
 
116
- arguments[:target][:client] ||= arguments[:source][:client]
133
+ arguments[:dest][:client] ||= arguments[:source][:client]
117
134
  end
118
135
 
119
136
  # Performs the operation
@@ -144,14 +161,14 @@ module Elasticsearch
144
161
  output[:errors] += bulk_response['items'].select { |k, v| k.values.first['error'] }.size
145
162
  end
146
163
 
147
- arguments[:target][:client].indices.refresh index: arguments[:target][:index] if arguments[:refresh]
164
+ arguments[:dest][:client].indices.refresh index: arguments[:dest][:index] if arguments[:refresh]
148
165
 
149
166
  output
150
167
  end
151
168
 
152
169
  def __store_batch(documents)
153
170
  body = documents.map do |doc|
154
- doc['_index'] = arguments[:target][:index]
171
+ doc['_index'] = arguments[:dest][:index]
155
172
 
156
173
  arguments[:transform].call(doc) if arguments[:transform]
157
174
 
@@ -162,7 +179,7 @@ module Elasticsearch
162
179
  { index: doc }
163
180
  end
164
181
 
165
- arguments[:target][:client].bulk body: body
182
+ arguments[:dest][:client].bulk body: body
166
183
  end
167
184
  end
168
185
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'elasticsearch/extensions/test/cluster'
2
19
 
3
20
  namespace :elasticsearch do
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'timeout'
2
19
  require 'net/http'
3
20
  require 'fileutils'
@@ -21,7 +38,6 @@ end
21
38
  module Elasticsearch
22
39
  module Extensions
23
40
  module Test
24
-
25
41
  # A convenience Ruby class for starting and stopping an Elasticsearch cluster,
26
42
  # eg. for integration tests
27
43
  #
@@ -43,12 +59,11 @@ module Elasticsearch
43
59
  # @see Cluster#initialize
44
60
  #
45
61
  module Cluster
46
-
47
62
  # Starts a cluster
48
63
  #
49
64
  # @see Cluster#start
50
65
  #
51
- def start(arguments={})
66
+ def start(arguments = {})
52
67
  Cluster.new(arguments).start
53
68
  end
54
69
 
@@ -56,7 +71,7 @@ module Elasticsearch
56
71
  #
57
72
  # @see Cluster#stop
58
73
  #
59
- def stop(arguments={})
74
+ def stop(arguments = {})
60
75
  Cluster.new(arguments).stop
61
76
  end
62
77
 
@@ -64,7 +79,7 @@ module Elasticsearch
64
79
  #
65
80
  # @see Cluster#running?
66
81
  #
67
- def running?(arguments={})
82
+ def running?(arguments = {})
68
83
  Cluster.new(arguments).running?
69
84
  end
70
85
 
@@ -72,7 +87,7 @@ module Elasticsearch
72
87
  #
73
88
  # @see Cluster#wait_for_green
74
89
  #
75
- def wait_for_green(arguments={})
90
+ def wait_for_green(arguments = {})
76
91
  Cluster.new(arguments).wait_for_green
77
92
  end
78
93
 
@@ -190,6 +205,7 @@ module Elasticsearch
190
205
  -E path.repo=/tmp \
191
206
  -E repositories.url.allowed_urls=http://snapshot.test* \
192
207
  -E discovery.zen.minimum_master_nodes=#{arguments[:number_of_nodes]-1} \
208
+ #{'-E xpack.security.enabled=false' unless arguments[:dist] == 'oss'} \
193
209
  -E node.max_local_storage_nodes=#{arguments[:number_of_nodes]} \
194
210
  -E logger.level=#{ENV['DEBUG'] ? 'DEBUG' : 'INFO'} \
195
211
  #{arguments[:es_params]}
@@ -197,6 +213,7 @@ module Elasticsearch
197
213
  }
198
214
  }
199
215
  COMMANDS['7.0'] = COMMANDS['6.0'].clone
216
+ COMMANDS['8.0'] = COMMANDS['7.0'].clone
200
217
  COMMANDS.freeze
201
218
 
202
219
  # Create a new instance of the Cluster class
@@ -238,7 +255,11 @@ module Elasticsearch
238
255
  @arguments[:network_host] ||= ENV.fetch('TEST_CLUSTER_NETWORK_HOST', __default_network_host)
239
256
  @arguments[:quiet] ||= ! ENV.fetch('QUIET', '').empty?
240
257
 
241
- @clear_cluster = !!@arguments[:clear_cluster] || (ENV.fetch('TEST_CLUSTER_CLEAR', 'true') != 'false')
258
+ @clear_cluster = if @arguments[:clear_cluster].nil?
259
+ (ENV.fetch('TEST_CLUSTER_CLEAR', 'true') != 'false')
260
+ else
261
+ !!@arguments[:clear_cluster]
262
+ end
242
263
 
243
264
  # Make sure `cluster_name` is not dangerous
244
265
  raise ArgumentError, "The `cluster_name` argument cannot be empty string or a slash" \
@@ -408,7 +429,7 @@ module Elasticsearch
408
429
  '0.0.0.0'
409
430
  when /^2/
410
431
  '_local_'
411
- when /^5|^6|^7/
432
+ when /^5|^6|^7|^8/
412
433
  '_local_'
413
434
  else
414
435
  raise RuntimeError, "Cannot determine default network host from version [#{version}]"
@@ -455,8 +476,8 @@ module Elasticsearch
455
476
  arguments[:version]
456
477
  elsif File.exist?(path_to_lib) && !(jar = Dir.entries(path_to_lib).select { |f| f =~ /^elasticsearch\-\d/ }.first).nil?
457
478
  __log "Determining version from [#{jar}]" if ENV['DEBUG']
458
- if m = jar.match(/elasticsearch\-(\S+-)?(?<version>\d+\.\d+\.\d+).*/)
459
- m[:version]
479
+ if m = jar.match(/elasticsearch\-(\d+\.\d+\.\d+).*/)
480
+ m[1]
460
481
  else
461
482
  raise RuntimeError, "Cannot determine Elasticsearch version from jar [#{jar}]"
462
483
  end
@@ -508,7 +529,9 @@ module Elasticsearch
508
529
  raise RuntimeError, "Cannot determine Elasticsearch version from [#{arguments[:command]} --version] or [#{arguments[:command]} -v]"
509
530
  end
510
531
 
511
- if m = output.match(/Version: (\d\.\d.\d).*,/)
532
+ @dist = output.match(/Build: ([a-z]+)\//)&.[](1)
533
+
534
+ if(m = output.match(/Version: (\d+\.\d+.\d+).*,/))
512
535
  m[1]
513
536
  else
514
537
  raise RuntimeError, "Cannot determine Elasticsearch version from elasticsearch --version output [#{output}]"
@@ -528,6 +551,8 @@ module Elasticsearch
528
551
  '6.0'
529
552
  when /^7\..*/
530
553
  '7.0'
554
+ when /^8\..*/
555
+ '8.0'
531
556
  else
532
557
  raise RuntimeError, "Cannot determine major version from [#{version}]"
533
558
  end
@@ -540,11 +565,10 @@ module Elasticsearch
540
565
  # @return String
541
566
  #
542
567
  def __command(version, arguments, node_number)
543
- if command = COMMANDS[version]
544
- command.call(arguments, node_number)
545
- else
546
- raise ArgumentError, "Cannot find command for version [#{version}]"
547
- end
568
+ raise ArgumentError, "Cannot find command for version [#{version}]" unless (command = COMMANDS[version])
569
+
570
+ arguments.merge!({ dist: @dist })
571
+ command.call(arguments, node_number)
548
572
  end
549
573
 
550
574
  # Blocks the process and waits for the cluster to be in a "green" state
@@ -646,7 +670,6 @@ module Elasticsearch
646
670
  FileUtils.rm_rf arguments[:path_data]
647
671
  end
648
672
 
649
-
650
673
  # Check whether process for PIDs are running
651
674
  #
652
675
  # @api private
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'ruby-prof'
2
19
  require 'benchmark'
3
20
  require 'ansi'
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  module Elasticsearch
2
19
  module Extensions
3
20
  module Test
@@ -1,5 +1,22 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  module Elasticsearch
2
19
  module Extensions
3
- VERSION = "0.0.31"
20
+ VERSION = '0.0.33'.freeze
4
21
  end
5
22
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # encoding: utf-8
2
19
 
3
20
  require 'elasticsearch'
@@ -1 +1,6 @@
1
+ # Licensed to Elasticsearch B.V under one or more agreements.
2
+ # Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
+ # See the LICENSE file in the project root for more information
4
+ #
5
+
1
6
  require 'elasticsearch/extensions'
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'test_helper'
2
19
  require 'elasticsearch/extensions/ansi'
3
20
 
@@ -7,10 +24,10 @@ class Elasticsearch::Extensions::AnsiTest < Elasticsearch::Test::UnitTestCase
7
24
  @client = Elasticsearch::Client.new
8
25
  @client.stubs(:perform_request).returns \
9
26
  Elasticsearch::Transport::Transport::Response.new(200, { "ok" => true, "status" => 200, "name" => "Hit-Maker",
10
- "version" => { "number" => "0.90.7",
11
- "build_hash" => "abc123",
12
- "build_timestamp"=>"2013-11-13T12:06:54Z", "build_snapshot"=>false, "lucene_version"=>"4.5.1" },
13
- "tagline"=>"You Know, for Search" })
27
+ "version" => { "number" => "0.90.7",
28
+ "build_hash" => "abc123",
29
+ "build_timestamp"=>"2013-11-13T12:06:54Z", "build_snapshot"=>false, "lucene_version"=>"4.5.1" },
30
+ "tagline"=>"You Know, for Search" })
14
31
  end
15
32
 
16
33
  should "wrap the response" do
@@ -30,7 +47,7 @@ class Elasticsearch::Extensions::AnsiTest < Elasticsearch::Test::UnitTestCase
30
47
  should "call the 'awesome_inspect' method when available and no handler found" do
31
48
  @client.stubs(:perform_request).returns \
32
49
  Elasticsearch::Transport::Transport::Response.new(200, {"index-1"=>{"aliases"=>{}}})
33
- response = @client.indices.get_aliases
50
+ response = @client.cat.aliases
34
51
 
35
52
  response.instance_eval do
36
53
  def awesome_inspect; "---PRETTY---"; end
@@ -41,7 +58,7 @@ class Elasticsearch::Extensions::AnsiTest < Elasticsearch::Test::UnitTestCase
41
58
  should "call `to_s` method when no pretty printer or handler found" do
42
59
  @client.stubs(:perform_request).returns \
43
60
  Elasticsearch::Transport::Transport::Response.new(200, {"index-1"=>{"aliases"=>{}}})
44
- response = @client.indices.get_aliases
61
+ response = @client.cat.aliases
45
62
 
46
63
  assert_equal '{"index-1"=>{"aliases"=>{}}}', response.to_ansi
47
64
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'test_helper'
2
19
  require 'logger'
3
20
 
@@ -106,5 +123,9 @@ class Elasticsearch::Extensions::BackupTest < Elasticsearch::Test::UnitTestCase
106
123
 
107
124
  @subject.__perform_single
108
125
  end
126
+
127
+ should "sanitize filename" do
128
+ assert_equal "foo-bar-baz", @subject.__sanitize_filename("foo/bar\nbaz")
129
+ end
109
130
  end
110
131
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'test_helper'
2
19
  require 'elasticsearch/extensions/reindex'
3
20
 
@@ -17,7 +34,7 @@ class Elasticsearch::Extensions::ReindexIntegrationTest < Elasticsearch::Test::I
17
34
  ANSI.ansi(severity[0] + ' ', color, :faint) + ANSI.ansi(msg, :white, :faint) + "\n"
18
35
  end
19
36
 
20
- @client = Elasticsearch::Client.new host: "localhost:#{@port}", logger: @logger
37
+ @client = Elasticsearch::Client.new host: "#{TEST_HOST}:#{TEST_PORT}", logger: @logger
21
38
  @client.indices.delete index: '_all'
22
39
 
23
40
  @client.index index: 'test1', type: 'd', id: 1, body: { title: 'TEST 1', category: 'one' }
@@ -37,53 +54,53 @@ class Elasticsearch::Extensions::ReindexIntegrationTest < Elasticsearch::Test::I
37
54
  should "copy documents from one index to another" do
38
55
  reindex = Elasticsearch::Extensions::Reindex.new \
39
56
  source: { index: 'test1', client: @client },
40
- target: { index: 'test2' },
57
+ dest: { index: 'test2' },
41
58
  batch_size: 2,
42
59
  refresh: true
43
60
 
44
61
  result = reindex.perform
45
62
 
46
63
  assert_equal 0, result[:errors]
47
- assert_equal 3, @client.search(index: 'test2')['hits']['total']
64
+ assert_equal 3, @client.search(index: 'test2')['hits']['total']['value']
48
65
  end
49
66
 
50
67
  should "transform documents with a lambda" do
51
68
  reindex = Elasticsearch::Extensions::Reindex.new \
52
69
  source: { index: 'test1', client: @client },
53
- target: { index: 'test2' },
70
+ dest: { index: 'test2' },
54
71
  transform: lambda { |d| d['_source']['category'].upcase! },
55
72
  refresh: true
56
73
 
57
74
  result = reindex.perform
58
75
 
59
76
  assert_equal 0, result[:errors]
60
- assert_equal 3, @client.search(index: 'test2')['hits']['total']
77
+ assert_equal 3, @client.search(index: 'test2')['hits']['total']['value']
61
78
  assert_equal 'ONE', @client.get(index: 'test2', type: 'd', id: 1)['_source']['category']
62
79
  end
63
80
 
64
81
  should "return the number of errors" do
65
- @client.indices.create index: 'test3', body: { mappings: { d: { properties: { category: { type: 'integer' } }}}}
82
+ @client.indices.create index: 'test3', body: { mappings: { properties: { category: { type: 'integer' } }}}
66
83
  @client.cluster.health wait_for_status: 'yellow'
67
84
 
68
85
  reindex = Elasticsearch::Extensions::Reindex.new \
69
86
  source: { index: 'test1', client: @client },
70
- target: { index: 'test3' }
87
+ dest: { index: 'test3' }
71
88
 
72
89
  result = reindex.perform
73
90
 
74
91
  @client.indices.refresh index: 'test3'
75
92
 
76
93
  assert_equal 3, result[:errors]
77
- assert_equal 0, @client.search(index: 'test3')['hits']['total']
94
+ assert_equal 0, @client.search(index: 'test3')['hits']['total']['value']
78
95
  end
79
96
 
80
97
  should "reindex via the API integration" do
81
98
  @client.indices.create index: 'test4'
82
99
 
83
- @client.reindex source: { index: 'test1' }, target: { index: 'test4' }
100
+ @client.reindex source: { index: 'test1' }, dest: { index: 'test4' }
84
101
  @client.indices.refresh index: 'test4'
85
102
 
86
- assert_equal 3, @client.search(index: 'test4')['hits']['total']
103
+ assert_equal 3, @client.search(index: 'test4')['hits']['total']['value']
87
104
  end
88
105
  end
89
106
 
@@ -1,9 +1,26 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'test_helper'
2
19
  require 'elasticsearch/extensions/reindex'
3
20
 
4
21
  class Elasticsearch::Extensions::ReindexTest < Elasticsearch::Test::UnitTestCase
5
22
  context "The Reindex extension module" do
6
- DEFAULT_OPTIONS = { source: { index: 'foo', client: Object.new }, target: { index: 'bar' } }
23
+ DEFAULT_OPTIONS = { source: { index: 'foo', client: Object.new }, dest: { index: 'bar' } }
7
24
 
8
25
  should "require options" do
9
26
  assert_raise ArgumentError do
@@ -50,7 +67,7 @@ class Elasticsearch::Extensions::ReindexTest < Elasticsearch::Test::UnitTestCase
50
67
  should "scroll through the index and save batches in bulk" do
51
68
  client = mock()
52
69
  subject = Elasticsearch::Extensions::Reindex.new source: { index: 'foo', client: client },
53
- target: { index: 'bar' }
70
+ dest: { index: 'bar' }
54
71
 
55
72
  client.expects(:search)
56
73
  .returns({ '_scroll_id' => 'scroll_id_1' }.merge(Marshal.load(Marshal.dump(@default_response))))
@@ -70,7 +87,7 @@ class Elasticsearch::Extensions::ReindexTest < Elasticsearch::Test::UnitTestCase
70
87
  should "return the number of errors" do
71
88
  client = mock()
72
89
  subject = Elasticsearch::Extensions::Reindex.new source: { index: 'foo', client: client },
73
- target: { index: 'bar' }
90
+ dest: { index: 'bar' }
74
91
 
75
92
  client.expects(:search).returns({ '_scroll_id' => 'scroll_id_1' }.merge(@default_response))
76
93
  client.expects(:scroll).returns(@empty_response)
@@ -85,7 +102,7 @@ class Elasticsearch::Extensions::ReindexTest < Elasticsearch::Test::UnitTestCase
85
102
  client = mock()
86
103
  subject = Elasticsearch::Extensions::Reindex.new \
87
104
  source: { index: 'foo', client: client },
88
- target: { index: 'bar' },
105
+ dest: { index: 'bar' },
89
106
  transform: lambda { |d| d['_source']['foo'].upcase!; d }
90
107
 
91
108
  client.expects(:search).returns({ '_scroll_id' => 'scroll_id_1' }.merge(@default_response))
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'test_helper'
2
19
  require 'pathname'
3
20