ej 0.1.12 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ej/core.rb +2 -2
- data/lib/ej/util.rb +28 -0
- data/lib/ej/values.rb +2 -20
- data/lib/ej/version.rb +1 -1
- data/spec/util_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c2fa0d4e1e6e487bad78a7aca5dd1835cfb2081
|
4
|
+
data.tar.gz: 13aec98633b2fda985ae14ccfa320c9f28c73223
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 683b1f431d24d4adc5028bf5bda1056067c9a4d9bb4367506430a6b5a61af3f22c03107d28404bdb44c3db7d615baa697f3b8513bf39c48c32b9897d387dc229
|
7
|
+
data.tar.gz: 638fb4221ed2c5c743a13f950f7dadc1bcd24582e168c9d16a9002b192123d6d504e15bb7591753b8cf924ccb5171cbde5d874c6e7ae71bbc011c1c9aa2b97f0
|
data/lib/ej/core.rb
CHANGED
@@ -148,8 +148,8 @@ module Ej
|
|
148
148
|
end
|
149
149
|
|
150
150
|
def copy(source, dest, query, per_size, scroll, dest_index, slice_max)
|
151
|
-
source_client = Elasticsearch::Client.new
|
152
|
-
dest_client = Elasticsearch::Client.new
|
151
|
+
source_client = Elasticsearch::Client.new transport: Util.get_transport(Util.parse_hosts(source))
|
152
|
+
dest_client = Elasticsearch::Client.new transport: Util.get_transport(Util.parse_hosts(dest))
|
153
153
|
|
154
154
|
parallel_array = slice_max ? slice_max.times.to_a : [0]
|
155
155
|
Parallel.map(parallel_array, :in_processes=>parallel_array.size) do |slice_id|
|
data/lib/ej/util.rb
CHANGED
@@ -19,5 +19,33 @@ module Ej
|
|
19
19
|
def self.get_sources(results)
|
20
20
|
results.hits.hits.map { |result| result._source }
|
21
21
|
end
|
22
|
+
|
23
|
+
def self.get_transport(hosts)
|
24
|
+
transport = ::Elasticsearch::Transport::Transport::HTTP::Faraday.new(
|
25
|
+
{
|
26
|
+
hosts: hosts,
|
27
|
+
options: {
|
28
|
+
reload_connections: true,
|
29
|
+
reload_on_failure: false,
|
30
|
+
retry_on_failure: 5,
|
31
|
+
transport_options: {
|
32
|
+
headers: { 'Content-Type' => 'application/json' },
|
33
|
+
request: { timeout: 300 }
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
)
|
38
|
+
return transport
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.parse_hosts(host_string, user = nil, password = nil)
|
42
|
+
host, port = (host_string || DEFAULT_HOST), DEFAULT_PORT
|
43
|
+
if !host_string.nil? && host_string.include?(":")
|
44
|
+
host, port = host_string.split(':')
|
45
|
+
end
|
46
|
+
|
47
|
+
hosts = [{ host: host, port: port.to_i, user: user, password: password }]
|
48
|
+
return hosts
|
49
|
+
end
|
22
50
|
end
|
23
51
|
end
|
data/lib/ej/values.rb
CHANGED
@@ -12,26 +12,8 @@ module Ej
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def get_client(host_string, index, user, password)
|
15
|
-
|
16
|
-
|
17
|
-
host, port = host_string.split(':')
|
18
|
-
end
|
19
|
-
|
20
|
-
hosts = [{ host: host, port: port, user: user, password: password }]
|
21
|
-
transport = ::Elasticsearch::Transport::Transport::HTTP::Faraday.new(
|
22
|
-
{
|
23
|
-
hosts: hosts,
|
24
|
-
options: {
|
25
|
-
reload_connections: true,
|
26
|
-
reload_on_failure: false,
|
27
|
-
retry_on_failure: 5,
|
28
|
-
transport_options: {
|
29
|
-
request: { timeout: 300 }
|
30
|
-
}
|
31
|
-
}
|
32
|
-
}
|
33
|
-
)
|
34
|
-
::Elasticsearch::Client.new transport: transport, index: index, logger: @logger
|
15
|
+
hosts = Util.parse_hosts(host_string, user, password)
|
16
|
+
::Elasticsearch::Client.new transport: Util.get_transport(hosts), index: index, logger: @logger
|
35
17
|
end
|
36
18
|
end
|
37
19
|
end
|
data/lib/ej/version.rb
CHANGED
data/spec/util_spec.rb
CHANGED
@@ -31,6 +31,13 @@ describe Ej::Util do
|
|
31
31
|
Util.generate_id('%s_%s', {"id" => 1, "name" => "rspec"}, ['id', 'name']).should == '1_rspec'
|
32
32
|
end
|
33
33
|
|
34
|
+
it "parse hosts" do
|
35
|
+
Util.parse_hosts(nil).should == [{ host: 'localhost', port: 9200, user: nil, password: nil }]
|
36
|
+
Util.parse_hosts("localhost").should == [{ host: 'localhost', port: 9200, user: nil, password: nil }]
|
37
|
+
Util.parse_hosts("localhost:9100").should == [{ host: 'localhost', port: 9100, user: nil, password: nil }]
|
38
|
+
Util.parse_hosts("localhost:9100", 'user', 'password').should == [{ host: 'localhost', port: 9100, user: 'user', password: 'password' }]
|
39
|
+
end
|
40
|
+
|
34
41
|
after do
|
35
42
|
end
|
36
43
|
end
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toyama0919
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|