ej 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ej/commands.rb +5 -1
- data/lib/ej/core.rb +7 -6
- data/lib/ej/values.rb +3 -3
- data/lib/ej/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e76e6b6fc5c6bebf55f97553afc843cbb9d9b730
|
4
|
+
data.tar.gz: '07830f36bd93af33e7686d264ef25dcf5b34d10b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96e69fe5ee1ba6ae3ecb8c53030b6710379bd312f8bef4ffcc5cea5d5e0281bfc3f11478b743d37122fcf01c5d06fe5476f4103805d18105a77f5a30c1926458
|
7
|
+
data.tar.gz: 9788d2673c94ac4f30084fc7951f660484268e440934a45495bfbe12ff1aeaa503708ff1af36c3b96d74b0539e75ed0df15816668d2602a9c36fde4b81aac3b5
|
data/lib/ej/commands.rb
CHANGED
@@ -6,6 +6,8 @@ module Ej
|
|
6
6
|
class Commands < Thor
|
7
7
|
class_option :index, aliases: '-i', type: :string, default: '_all', desc: 'index'
|
8
8
|
class_option :host, aliases: '-h', type: :string, default: DEFAULT_HOST, desc: 'host'
|
9
|
+
class_option :user, aliases: '-u', type: :string, default: nil, desc: 'user'
|
10
|
+
class_option :password, aliases: '--pass', type: :string, default: nil, desc: 'password'
|
9
11
|
class_option :debug, aliases: '-d', type: :boolean, default: false, desc: 'debug mode'
|
10
12
|
|
11
13
|
map '-s' => :search
|
@@ -68,13 +70,15 @@ module Ej
|
|
68
70
|
option :query, type: :string, aliases: '-q', default: nil, desc: 'query'
|
69
71
|
option :per, type: :numeric, default: nil, desc: 'per'
|
70
72
|
option :scroll, type: :string, default: "1m", desc: 'scroll'
|
73
|
+
option :dest_index, type: :string, desc: 'dest index'
|
71
74
|
def copy
|
72
75
|
@core.copy(
|
73
76
|
options[:source],
|
74
77
|
options[:dest],
|
75
78
|
options[:query],
|
76
79
|
options[:per],
|
77
|
-
options[:scroll]
|
80
|
+
options[:scroll],
|
81
|
+
options[:dest_index]
|
78
82
|
)
|
79
83
|
end
|
80
84
|
|
data/lib/ej/core.rb
CHANGED
@@ -147,7 +147,7 @@ module Ej
|
|
147
147
|
connect_with_retry { @client.bulk body: bulk_message unless bulk_message.empty? }
|
148
148
|
end
|
149
149
|
|
150
|
-
def copy(source, dest, query, per_size, scroll)
|
150
|
+
def copy(source, dest, query, per_size, scroll, dest_index)
|
151
151
|
source_client = Elasticsearch::Client.new hosts: source
|
152
152
|
dest_client = Elasticsearch::Client.new hosts: dest
|
153
153
|
|
@@ -155,18 +155,18 @@ module Ej
|
|
155
155
|
r = connect_with_retry { source_client.search(scroll_option) }
|
156
156
|
total = r['hits']['total']
|
157
157
|
i = 0
|
158
|
-
i += bulk_results(r, dest_client, i, total)
|
158
|
+
i += bulk_results(r, dest_client, i, total, dest_index)
|
159
159
|
|
160
160
|
while r = connect_with_retry { source_client.scroll(scroll_id: r['_scroll_id'], scroll: scroll) } and
|
161
161
|
(not r['hits']['hits'].empty?) do
|
162
|
-
i += bulk_results(r, dest_client, i, total)
|
162
|
+
i += bulk_results(r, dest_client, i, total, dest_index)
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
166
|
private
|
167
167
|
|
168
|
-
def bulk_results(results, dest_client, before_size, total)
|
169
|
-
bulk_message = convert_results(results)
|
168
|
+
def bulk_results(results, dest_client, before_size, total, dest_index)
|
169
|
+
bulk_message = convert_results(results, dest_index)
|
170
170
|
connect_with_retry do
|
171
171
|
dest_client.bulk body: bulk_message unless bulk_message.empty?
|
172
172
|
to_size = before_size + (bulk_message.size/2)
|
@@ -182,7 +182,7 @@ module Ej
|
|
182
182
|
search_option
|
183
183
|
end
|
184
184
|
|
185
|
-
def convert_results(search_results)
|
185
|
+
def convert_results(search_results, dest_index)
|
186
186
|
data = HashWrapper.new(search_results)
|
187
187
|
docs = data.hits.hits
|
188
188
|
bulk_message = []
|
@@ -192,6 +192,7 @@ module Ej
|
|
192
192
|
['_id', '_type', '_index'].each do |meta_field|
|
193
193
|
source.delete(meta_field)
|
194
194
|
end
|
195
|
+
doc._index = dest_index if dest_index
|
195
196
|
bulk_message << { index: doc.to_h }
|
196
197
|
bulk_message << source
|
197
198
|
end
|
data/lib/ej/values.rb
CHANGED
@@ -7,17 +7,17 @@ module Ej
|
|
7
7
|
def initialize(global_options)
|
8
8
|
@logger = Logger.new($stderr)
|
9
9
|
@logger.level = global_options[:debug] ? Logger::DEBUG : Logger::INFO
|
10
|
-
@client = get_client(global_options[:host], global_options[:index])
|
10
|
+
@client = get_client(global_options[:host], global_options[:index], global_options[:user], global_options[:password])
|
11
11
|
@index = global_options[:index]
|
12
12
|
end
|
13
13
|
|
14
|
-
def get_client(host_string, index)
|
14
|
+
def get_client(host_string, index, user, password)
|
15
15
|
host, port = (host_string || DEFAULT_HOST), DEFAULT_PORT
|
16
16
|
if !host_string.nil? && host_string.include?(":")
|
17
17
|
host, port = host_string.split(':')
|
18
18
|
end
|
19
19
|
|
20
|
-
hosts = [{ host: host, port: port }]
|
20
|
+
hosts = [{ host: host, port: port, user: user, password: password }]
|
21
21
|
transport = ::Elasticsearch::Transport::Transport::HTTP::Faraday.new(
|
22
22
|
{
|
23
23
|
hosts: hosts,
|
data/lib/ej/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ej
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toyama0919
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06
|
11
|
+
date: 2017-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -204,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
204
|
version: '0'
|
205
205
|
requirements: []
|
206
206
|
rubyforge_project:
|
207
|
-
rubygems_version: 2.
|
207
|
+
rubygems_version: 2.6.13
|
208
208
|
signing_key:
|
209
209
|
specification_version: 4
|
210
210
|
summary: elasticsearch command line utility.
|