elasticsearch-extensions 0.0.31 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,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/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
  # encoding: utf-8
2
19
 
3
20
  module Elasticsearch
@@ -100,7 +117,7 @@ module Elasticsearch
100
117
  output << ""
101
118
  end
102
119
  output << Helpers.___
103
- output << "#{hits.size.to_s.ansi(:bold)} of #{json['hits']['total'].to_s.ansi(:bold)} results".ansi(:faint)
120
+ output << "#{hits.size.to_s.ansi(:bold)} of #{json['hits']['total']['value'].to_s.ansi(:bold)} results".ansi(:faint)
104
121
 
105
122
  output.join("\n")
106
123
  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
  module Elasticsearch
@@ -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 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
  # encoding: utf-8
2
19
 
3
20
  require 'pathname'
@@ -17,6 +34,7 @@ rescue LoadError
17
34
  warn('The "patron" gem could not be loaded. HTTP requests may not be performed optimally.')
18
35
  end
19
36
 
37
+
20
38
  require 'elasticsearch'
21
39
 
22
40
  module Backup
@@ -164,12 +182,19 @@ module Backup
164
182
  while r = client.scroll(scroll_id: r['_scroll_id'], scroll: scroll) and not r['hits']['hits'].empty? do
165
183
  r['hits']['hits'].each do |hit|
166
184
  FileUtils.mkdir_p "#{path.join hit['_index'], hit['_type']}"
167
- File.open("#{path.join hit['_index'], hit['_type'], hit['_id']}.json", 'w') do |file|
185
+ File.open("#{path.join hit['_index'], hit['_type'], __sanitize_filename(hit['_id'])}.json", 'w') do |file|
168
186
  file.write MultiJson.dump(hit)
169
187
  end
170
188
  end
171
189
  end
172
190
  end
191
+
192
+ def __sanitize_filename name
193
+ name
194
+ .encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�")
195
+ .strip
196
+ .tr("\u{202E}%$|:;/\t\r\n\\", "-")
197
+ end
173
198
  end
174
199
  end
175
200
  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
  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 '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 \
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}]"
@@ -451,12 +472,13 @@ module Elasticsearch
451
472
  #
452
473
  def __determine_version
453
474
  path_to_lib = File.dirname(arguments[:command]) + '/../lib/'
475
+
454
476
  version = if arguments[:version]
455
477
  arguments[:version]
456
478
  elsif File.exist?(path_to_lib) && !(jar = Dir.entries(path_to_lib).select { |f| f =~ /^elasticsearch\-\d/ }.first).nil?
457
479
  __log "Determining version from [#{jar}]" if ENV['DEBUG']
458
- if m = jar.match(/elasticsearch\-(\S+-)?(?<version>\d+\.\d+\.\d+).*/)
459
- m[:version]
480
+ if m = jar.match(/elasticsearch\-(\d+\.\d+\.\d+).*/)
481
+ m[1]
460
482
  else
461
483
  raise RuntimeError, "Cannot determine Elasticsearch version from jar [#{jar}]"
462
484
  end
@@ -508,7 +530,7 @@ module Elasticsearch
508
530
  raise RuntimeError, "Cannot determine Elasticsearch version from [#{arguments[:command]} --version] or [#{arguments[:command]} -v]"
509
531
  end
510
532
 
511
- if m = output.match(/Version: (\d\.\d.\d).*,/)
533
+ if(m = output.match(/Version: (\d+\.\d+.\d+).*,/))
512
534
  m[1]
513
535
  else
514
536
  raise RuntimeError, "Cannot determine Elasticsearch version from elasticsearch --version output [#{output}]"
@@ -528,6 +550,8 @@ module Elasticsearch
528
550
  '6.0'
529
551
  when /^7\..*/
530
552
  '7.0'
553
+ when /^8\..*/
554
+ '8.0'
531
555
  else
532
556
  raise RuntimeError, "Cannot determine major version from [#{version}]"
533
557
  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 'ruby-prof'
2
19
  require 'benchmark'
3
20
  require 'ansi'