es_importer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +115 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/es_importer.gemspec +34 -0
- data/lib/es_importer/version.rb +3 -0
- data/lib/es_importer.rb +148 -0
- metadata +184 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 128cea52bee57453bd7676e12976bfcdf910aa54
|
4
|
+
data.tar.gz: b2017bf956da03ee8e37fe55a5b62a4021d8bbcd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bbe4876a6d400599f8b7ed3561c71f9171fcd3b182975df57633dff793fbf6b50bb8a15293c3c084b1f22b76a94592353e67cfce96528a3bd9b02ee079fff2b3
|
7
|
+
data.tar.gz: add933d42aaae36fbe2f0a6a7a2f714706c1aa5c8ac29fd97606ca9eed633906aa075a8147ca9f8ad91aa36212f58441e061bd1e72ca2df344560ba313d66649
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at damir.roso@nih.gov. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
es_importer (0.1.0)
|
5
|
+
aws-sdk
|
6
|
+
elasticsearch
|
7
|
+
faraday
|
8
|
+
faraday_middleware
|
9
|
+
faraday_middleware-aws-signers-v4
|
10
|
+
typhoeus
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
aws-sdk (2.10.105)
|
16
|
+
aws-sdk-resources (= 2.10.105)
|
17
|
+
aws-sdk-core (2.10.105)
|
18
|
+
aws-sigv4 (~> 1.0)
|
19
|
+
jmespath (~> 1.0)
|
20
|
+
aws-sdk-resources (2.10.105)
|
21
|
+
aws-sdk-core (= 2.10.105)
|
22
|
+
aws-sigv4 (1.0.2)
|
23
|
+
diff-lcs (1.3)
|
24
|
+
elasticsearch (6.0.2)
|
25
|
+
elasticsearch-api (= 6.0.2)
|
26
|
+
elasticsearch-transport (= 6.0.2)
|
27
|
+
elasticsearch-api (6.0.2)
|
28
|
+
multi_json
|
29
|
+
elasticsearch-transport (6.0.2)
|
30
|
+
faraday
|
31
|
+
multi_json
|
32
|
+
ethon (0.11.0)
|
33
|
+
ffi (>= 1.3.0)
|
34
|
+
faraday (0.14.0)
|
35
|
+
multipart-post (>= 1.2, < 3)
|
36
|
+
faraday_middleware (0.12.2)
|
37
|
+
faraday (>= 0.7.4, < 1.0)
|
38
|
+
faraday_middleware-aws-signers-v4 (0.1.9)
|
39
|
+
aws-sdk-resources (>= 2, < 3)
|
40
|
+
faraday (~> 0.9)
|
41
|
+
ffi (1.9.23)
|
42
|
+
jmespath (1.3.1)
|
43
|
+
multi_json (1.13.1)
|
44
|
+
multipart-post (2.0.0)
|
45
|
+
rake (10.5.0)
|
46
|
+
rspec (3.7.0)
|
47
|
+
rspec-core (~> 3.7.0)
|
48
|
+
rspec-expectations (~> 3.7.0)
|
49
|
+
rspec-mocks (~> 3.7.0)
|
50
|
+
rspec-core (3.7.1)
|
51
|
+
rspec-support (~> 3.7.0)
|
52
|
+
rspec-expectations (3.7.0)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.7.0)
|
55
|
+
rspec-mocks (3.7.0)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.7.0)
|
58
|
+
rspec-support (3.7.1)
|
59
|
+
typhoeus (1.3.0)
|
60
|
+
ethon (>= 0.9.0)
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
bundler (~> 1.16)
|
67
|
+
es_importer!
|
68
|
+
rake (~> 10.0)
|
69
|
+
rspec (~> 3.0)
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Damir Roso
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# Elasticsearch importer
|
2
|
+
Transform and import JSON documents into elastic search. Configure indices and transformations with ruby hash.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'es_importer'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install es_importer
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
See inline coments:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'es_importer'
|
26
|
+
|
27
|
+
# configure client
|
28
|
+
EsImporter.configure('http://localhost:9200')
|
29
|
+
|
30
|
+
# generate some users
|
31
|
+
users = (1..100).to_a.map do |i|
|
32
|
+
{ user_id: i,
|
33
|
+
first_name: 'John',
|
34
|
+
last_name: 'Doe',
|
35
|
+
created_at: Time.now.iso8601,
|
36
|
+
active: true,
|
37
|
+
email: "USER_#{i}@example.com",
|
38
|
+
country_code: 'US',
|
39
|
+
friends: {
|
40
|
+
US: ['Joe']
|
41
|
+
}
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
# define elastic id, mapping and keywords for index; provide conversion procs
|
46
|
+
importer = {
|
47
|
+
|
48
|
+
# name of the index
|
49
|
+
users: {
|
50
|
+
|
51
|
+
# build id from single or multiple keys
|
52
|
+
id_key: [:user_id, :created_at],
|
53
|
+
|
54
|
+
# define index mapping
|
55
|
+
mapping: {
|
56
|
+
user_id: :text,
|
57
|
+
active: :boolean,
|
58
|
+
email: :text,
|
59
|
+
created_at: :date,
|
60
|
+
country_code: :text
|
61
|
+
},
|
62
|
+
|
63
|
+
# keyword generated is 'country_code.keyword'
|
64
|
+
keywords: [:country_code],
|
65
|
+
|
66
|
+
converters: {
|
67
|
+
# downcase existing field value, second argument is document being processed
|
68
|
+
'email' => Proc.new{|attr, _| attr.downcase},
|
69
|
+
|
70
|
+
# add new entry to array under existing nested key
|
71
|
+
'friends.US' => Proc.new{|attr| attr << 'Marry'},
|
72
|
+
|
73
|
+
# generate new key with composite value
|
74
|
+
'full_name' => Proc.new{|doc| "#{doc['first_name']} #{doc['last_name']}"},
|
75
|
+
|
76
|
+
# generate new nested key as array
|
77
|
+
'profile.emails' => Proc.new{|doc| [doc['email']]}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
# register importer
|
83
|
+
EsImporter.add_importer(importer)
|
84
|
+
|
85
|
+
# create index
|
86
|
+
EsImporter.create_index!(:users)
|
87
|
+
|
88
|
+
# import users
|
89
|
+
EsImporter.import(:users, users)
|
90
|
+
|
91
|
+
# delete index
|
92
|
+
EsImporter.delete_index!(:users)
|
93
|
+
|
94
|
+
```
|
95
|
+
|
96
|
+
AWS elastic instance is also supported, region is extracted from url and credentials are set form ruby SDK.
|
97
|
+
|
98
|
+
|
99
|
+
## Development
|
100
|
+
|
101
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
102
|
+
|
103
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
104
|
+
|
105
|
+
## Contributing
|
106
|
+
|
107
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/es_importer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
108
|
+
|
109
|
+
## License
|
110
|
+
|
111
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
112
|
+
|
113
|
+
## Code of Conduct
|
114
|
+
|
115
|
+
Everyone interacting in the EsImporter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/es_importer/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "es_importer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/es_importer.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "es_importer/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "es_importer"
|
8
|
+
spec.version = EsImporter::VERSION
|
9
|
+
spec.authors = ["Damir Roso"]
|
10
|
+
spec.email = ["damir.roso@nih.gov"]
|
11
|
+
|
12
|
+
spec.summary = %q{Transform and import JSON documents into elastic search.}
|
13
|
+
spec.description = %q{Configure indices and transformations with ruby hash.}
|
14
|
+
spec.homepage = "https://github.com/damir/es_importer"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
|
28
|
+
spec.add_dependency 'aws-sdk'
|
29
|
+
spec.add_dependency 'elasticsearch'
|
30
|
+
spec.add_dependency 'faraday'
|
31
|
+
spec.add_dependency 'faraday_middleware'
|
32
|
+
spec.add_dependency 'faraday_middleware-aws-signers-v4'
|
33
|
+
spec.add_dependency 'typhoeus'
|
34
|
+
end
|
data/lib/es_importer.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
require "es_importer/version"
|
2
|
+
require 'elasticsearch'
|
3
|
+
|
4
|
+
module EsImporter
|
5
|
+
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# configure state and return es client
|
9
|
+
def configure(uri, logger: nil)
|
10
|
+
@importers = {}
|
11
|
+
@logger = logger
|
12
|
+
@es_uri = uri
|
13
|
+
@client = Elasticsearch::Client.new transport: transport
|
14
|
+
end
|
15
|
+
|
16
|
+
# init es transport
|
17
|
+
def transport
|
18
|
+
# parse uri for host configuration
|
19
|
+
es_uri = URI.parse(@es_uri)
|
20
|
+
host_config = {host: es_uri.host, port: es_uri.port, scheme: es_uri.scheme}
|
21
|
+
|
22
|
+
# aws support
|
23
|
+
if is_amazon_uri = es_uri.host.include?('es.amazonaws.com')
|
24
|
+
require 'aws-sdk'
|
25
|
+
require 'faraday_middleware/aws_signers_v4'
|
26
|
+
aws_region = es_uri.host.split('.')[-4]
|
27
|
+
credentials = Aws::ElasticsearchService::Client.new(region: aws_region).instance_eval{@config.credentials}
|
28
|
+
end
|
29
|
+
|
30
|
+
faraday_config = lambda do |faraday|
|
31
|
+
# sign for aws
|
32
|
+
faraday.request :aws_signers_v4,
|
33
|
+
{ credentials: credentials,
|
34
|
+
service_name: 'es',
|
35
|
+
region: aws_region} if is_amazon_uri
|
36
|
+
faraday.headers['Content-Type'] = 'application/json'
|
37
|
+
faraday.adapter :typhoeus
|
38
|
+
end
|
39
|
+
Elasticsearch::Transport::Transport::HTTP::Faraday.new(hosts: [host_config], &faraday_config)
|
40
|
+
end
|
41
|
+
|
42
|
+
# save importer
|
43
|
+
def add_importer(importer)
|
44
|
+
@importers.update(importer)
|
45
|
+
end
|
46
|
+
|
47
|
+
# create es index
|
48
|
+
def create_index!(es_index)
|
49
|
+
puts "Creating #{es_index} index at #{@es_uri} ..."
|
50
|
+
@client.indices.create index: es_index, body: {
|
51
|
+
mappings: {
|
52
|
+
es_index.to_s.chomp('s') => {
|
53
|
+
dynamic: false,
|
54
|
+
properties: @importers.dig(es_index, :mapping).reduce({}){|a, (k,v)| a.update({k => {type: v}.update(@importers.dig(es_index, :keywords)&.include?(k) ? {fields: {keyword: {type: :keyword}}} : {})})}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
rescue => error
|
59
|
+
puts "Error creating #{es_index} index. #{error.class}: #{error.message}"
|
60
|
+
raise
|
61
|
+
end
|
62
|
+
|
63
|
+
# create es index
|
64
|
+
def delete_index!(es_index)
|
65
|
+
puts "Deleting #{es_index} index at #{@es_uri} ..."
|
66
|
+
@client.indices.delete index: es_index
|
67
|
+
rescue => error
|
68
|
+
puts "Error deleting #{es_index} index. #{error.class}: #{error.message}"
|
69
|
+
raise
|
70
|
+
end
|
71
|
+
|
72
|
+
# import documents
|
73
|
+
def import(es_index, documents)
|
74
|
+
|
75
|
+
# import stats init
|
76
|
+
start_time = Time.now
|
77
|
+
failed = 0; imported = 0
|
78
|
+
|
79
|
+
# insert into elastic
|
80
|
+
documents.each_with_index do |document, index|
|
81
|
+
|
82
|
+
# convert all keys to strings
|
83
|
+
document = _deep_transform_keys_in_object(document, &:to_s)
|
84
|
+
|
85
|
+
# generate id
|
86
|
+
id_key = @importers.dig(es_index, :id_key)
|
87
|
+
id = document[id_key.to_s] if id_key.is_a?(Symbol) # single key
|
88
|
+
id = id_key.reduce([]){|acc, key| acc << document[key.to_s]}.join('-') if id_key.is_a?(Array) # composite key
|
89
|
+
|
90
|
+
# convert keys or add new ones
|
91
|
+
@importers.dig(es_index, :converters)&.each do |keys, converter|
|
92
|
+
keys = keys.split('.')
|
93
|
+
|
94
|
+
# transform existing key
|
95
|
+
if value = document.dig(*keys)
|
96
|
+
document[keys.first] = converter.call(value, document) if keys.size == 1 # lvl 1
|
97
|
+
keys.first(keys.size-1).reduce(document, :fetch)[keys.last] = converter.call(value, document) if keys.size > 1 # lvl > 1
|
98
|
+
|
99
|
+
# add new key
|
100
|
+
else
|
101
|
+
missing_key_index = nil
|
102
|
+
keys.each_with_index do |key, index|
|
103
|
+
missing_key_index = index and break unless document.dig(*keys.first(index + 1))
|
104
|
+
end
|
105
|
+
|
106
|
+
tail_keys = keys[missing_key_index..-1]
|
107
|
+
tail_hash = keys[0...missing_key_index].reduce(document, :fetch)
|
108
|
+
|
109
|
+
tail_keys.each_with_index do |key, index|
|
110
|
+
tail_hash[tail_keys[index]] = tail_keys.size == index + 1 ? converter.call(document) : {}
|
111
|
+
tail_hash = tail_hash[tail_keys[index]]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
begin
|
117
|
+
@client.index index: es_index, type: es_index.to_s.chomp('s'), id: id, body: document
|
118
|
+
puts "##{index + 1} imported #{id}" if @logger
|
119
|
+
imported = imported + 1
|
120
|
+
rescue => e
|
121
|
+
puts "##{index + 1} failed #{id}" if @logger
|
122
|
+
puts e.class; puts e.message
|
123
|
+
failed = failed + 1
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# print import statistics
|
128
|
+
puts; puts "#{es_index} import statistics"; puts '-' * 100
|
129
|
+
puts "Failed: #{failed}"
|
130
|
+
puts "Imported: #{imported}"
|
131
|
+
puts "Time spent: #{Time.now - start_time} sec"
|
132
|
+
puts
|
133
|
+
end
|
134
|
+
|
135
|
+
# taken from https://github.com/rails/rails/blob/f213e926892020f9ab6c8974612c59e2ba959253/activesupport/lib/active_support/core_ext/hash/keys.rb#L145
|
136
|
+
def _deep_transform_keys_in_object(object, &block)
|
137
|
+
case object
|
138
|
+
when Hash
|
139
|
+
object.each_with_object({}) do |(key, value), result|
|
140
|
+
result[yield(key)] = _deep_transform_keys_in_object(value, &block)
|
141
|
+
end
|
142
|
+
when Array
|
143
|
+
object.map { |e| _deep_transform_keys_in_object(e, &block) }
|
144
|
+
else
|
145
|
+
object
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: es_importer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Damir Roso
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: elasticsearch
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday_middleware
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: faraday_middleware-aws-signers-v4
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: typhoeus
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Configure indices and transformations with ruby hash.
|
140
|
+
email:
|
141
|
+
- damir.roso@nih.gov
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".travis.yml"
|
149
|
+
- CODE_OF_CONDUCT.md
|
150
|
+
- Gemfile
|
151
|
+
- Gemfile.lock
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- bin/console
|
156
|
+
- bin/setup
|
157
|
+
- es_importer.gemspec
|
158
|
+
- lib/es_importer.rb
|
159
|
+
- lib/es_importer/version.rb
|
160
|
+
homepage: https://github.com/damir/es_importer
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata: {}
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
requirements: []
|
179
|
+
rubyforge_project:
|
180
|
+
rubygems_version: 2.5.2
|
181
|
+
signing_key:
|
182
|
+
specification_version: 4
|
183
|
+
summary: Transform and import JSON documents into elastic search.
|
184
|
+
test_files: []
|