es-reindex 0.3.1 → 0.3.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +2 -1
- data/es-reindex.gemspec +0 -1
- data/lib/es-reindex.rb +17 -10
- data/lib/es-reindex/version.rb +1 -1
- data/spec/integration/copy_spec.rb +10 -0
- data/spec/integration/reindex_spec.rb +21 -6
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb1862c74c923e6e30a22bc694f2b4cc97a11ac
|
4
|
+
data.tar.gz: bc5529358af365d1803a6d5c5a5158c6e265fd36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eec5cb2304c337e4fd242f2035d99354f1542939948830292f5a94f4a1d4d684e066f1a6cd576e23f27fac84678d203d9fad544ce81235c337beeff0ec8b99d
|
7
|
+
data.tar.gz: 341436662c907031f3ed38ead2e96dca6a2228203b47b6c70d5d7a1f6a9f84cd648c01d5b61d0332dc30f2811057f603660ecb061d647b7269772ee8fd69ccd7
|
data/CHANGELOG.markdown
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
## Changelog
|
2
2
|
|
3
|
-
+ __0.3.
|
3
|
+
+ __0.3.2__: Remove activesupport dependency entirely, handle aliased indices [@waterlink](https://github.com/waterlink)
|
4
|
+
+ __0.3.1__: Add activesupport dependency since es-reindex uses methods from it.
|
4
5
|
+ __0.3.0__: Add `:if` and `:unless` callbacks
|
5
6
|
+ __0.2.1__: [BUGFIX] Improve callback presence check
|
6
7
|
+ __0.2.0__: Lots of bugfixes, use elasticsearch client gem, add .reindex! method and callbacks
|
data/es-reindex.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.require_paths = ["lib"]
|
24
24
|
|
25
25
|
s.add_runtime_dependency 'elasticsearch', '>= 1.0.0'
|
26
|
-
s.add_runtime_dependency 'activesupport', '>= 0'
|
27
26
|
|
28
27
|
# Development Dependencies:
|
29
28
|
s.add_development_dependency 'elasticsearch-persistence', '~> 0.1'
|
data/lib/es-reindex.rb
CHANGED
@@ -39,7 +39,7 @@ class ESReindex
|
|
39
39
|
%w{
|
40
40
|
if unless mappings settings before_create after_create before_each after_each after_copy
|
41
41
|
}.each do |callback|
|
42
|
-
if options
|
42
|
+
if options.has_key?(callback.to_sym) && !options[callback.to_sym].respond_to?(:call)
|
43
43
|
raise ArgumentError, "#{callback} must be a callable object"
|
44
44
|
end
|
45
45
|
end
|
@@ -65,8 +65,8 @@ class ESReindex
|
|
65
65
|
|
66
66
|
def okay_to_proceed?
|
67
67
|
okay = true
|
68
|
-
okay = options[:if].call(sclient, dclient) if options
|
69
|
-
okay = (okay && !(options[:unless].call sclient, dclient)) if options
|
68
|
+
okay = options[:if].call(sclient, dclient) if options.has_key?(:if)
|
69
|
+
okay = (okay && !(options[:unless].call sclient, dclient)) if options.has_key?(:unless)
|
70
70
|
log 'Skipping action due to guard callbacks' unless okay
|
71
71
|
okay
|
72
72
|
end
|
@@ -113,13 +113,13 @@ class ESReindex
|
|
113
113
|
create_msg = ""
|
114
114
|
end
|
115
115
|
|
116
|
-
options[:before_create].
|
116
|
+
options[:before_create] && options[:before_create].call
|
117
117
|
|
118
118
|
log "Creating '#{durl}/#{didx}' index#{create_msg}..."
|
119
119
|
dclient.indices.create index: didx, body: { settings: settings, mappings: mappings }
|
120
120
|
log "Succesfully created '#{durl}/#{didx}''#{create_msg}."
|
121
121
|
|
122
|
-
options[:after_create].
|
122
|
+
options[:after_create] && options[:after_create].call
|
123
123
|
end
|
124
124
|
|
125
125
|
true
|
@@ -131,7 +131,7 @@ class ESReindex
|
|
131
131
|
return false
|
132
132
|
end
|
133
133
|
|
134
|
-
@settings = settings
|
134
|
+
@settings = fetch_index_config(settings, sidx)["settings"]
|
135
135
|
@settings["index"]["version"].delete "created"
|
136
136
|
end
|
137
137
|
|
@@ -140,7 +140,7 @@ class ESReindex
|
|
140
140
|
log "Failed to obtain original index '#{surl}/#{sidx}' mappings!", :error
|
141
141
|
return false
|
142
142
|
end
|
143
|
-
@mappings = mappings
|
143
|
+
@mappings = fetch_index_config(mappings, sidx)["mappings"]
|
144
144
|
end
|
145
145
|
|
146
146
|
def copy_docs
|
@@ -157,13 +157,13 @@ class ESReindex
|
|
157
157
|
while scroll = sclient.scroll(scroll_id: scroll['_scroll_id'], scroll: '10m') and not scroll['hits']['hits'].empty? do
|
158
158
|
bulk = []
|
159
159
|
scroll['hits']['hits'].each do |doc|
|
160
|
-
options[:before_each].
|
160
|
+
options[:before_each] && options[:before_each].call
|
161
161
|
### === implement possible modifications to the document
|
162
162
|
### === end modifications to the document
|
163
163
|
base = {'_index' => didx, '_id' => doc['_id'], '_type' => doc['_type'], data: doc['_source']}
|
164
164
|
bulk << {action => base}
|
165
165
|
@done = done + 1
|
166
|
-
options[:after_each].
|
166
|
+
options[:after_each] && options[:after_each].call
|
167
167
|
end
|
168
168
|
unless bulk.empty?
|
169
169
|
dclient.bulk body: bulk
|
@@ -175,7 +175,7 @@ class ESReindex
|
|
175
175
|
|
176
176
|
log "Copy progress: %u/%u done in %s.\n" % [done, total, tm_len]
|
177
177
|
|
178
|
-
options[:after_copy].
|
178
|
+
options[:after_copy] && options[:after_copy].call
|
179
179
|
|
180
180
|
true
|
181
181
|
end
|
@@ -242,4 +242,11 @@ private
|
|
242
242
|
out
|
243
243
|
end
|
244
244
|
|
245
|
+
# Accounts for aliased indices. When index is aliased there will not
|
246
|
+
# be a key nor in settings, nor in mappings. But there will be the
|
247
|
+
# only key for original index name.
|
248
|
+
def fetch_index_config(config, index)
|
249
|
+
config.fetch(index) { config.values.first }
|
250
|
+
end
|
251
|
+
|
245
252
|
end
|
data/lib/es-reindex/version.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe "copy!", type: :integration do
|
4
4
|
let(:orig_index_name) { "test_index" }
|
5
5
|
let(:new_index_name) { "test_index_clone" }
|
6
|
+
let(:orig_index_alias) { "test_index_alias" }
|
6
7
|
|
7
8
|
let!(:original_klass) { test_klass index_name: orig_index_name }
|
8
9
|
let!(:new_klass) { test_klass index_name: new_index_name }
|
@@ -10,6 +11,9 @@ describe "copy!", type: :integration do
|
|
10
11
|
let(:test_post) { original_klass.create id: 1, text: 'test_post' }
|
11
12
|
let(:test_post_2) { new_klass.create id: 2, text: 'other_post' }
|
12
13
|
|
14
|
+
let(:elastic_client) { Elasticsearch::Client.new(host: ES_HOST, log: false) }
|
15
|
+
let(:alias_index) { elastic_client.indices.put_alias(index: orig_index_name, name: orig_index_alias) }
|
16
|
+
|
13
17
|
# Create the index (test_index) on the test_klass:
|
14
18
|
before do
|
15
19
|
original_klass.create_index!
|
@@ -22,6 +26,12 @@ describe "copy!", type: :integration do
|
|
22
26
|
expect(new_klass.find test_post.id).to be_present
|
23
27
|
end
|
24
28
|
|
29
|
+
it "copies the aliased index" do
|
30
|
+
alias_index
|
31
|
+
ESReindex.copy! "#{ES_HOST}/#{orig_index_alias}", "#{ES_HOST}/#{new_index_name}", {}
|
32
|
+
expect(new_klass.find test_post.id).to be_present
|
33
|
+
end
|
34
|
+
|
25
35
|
context "when the destination index already exists" do
|
26
36
|
|
27
37
|
# Create the index (test_index_clone) on the destination klass:
|
@@ -3,12 +3,16 @@ require 'spec_helper'
|
|
3
3
|
describe "reindex!", type: :integration do
|
4
4
|
let(:orig_index_name) { "test_index" }
|
5
5
|
let(:new_index_name) { "test_index_clone" }
|
6
|
+
let(:orig_index_alias) { "test_index_alias" }
|
6
7
|
|
7
8
|
let!(:original_klass) { test_klass index_name: orig_index_name }
|
8
9
|
let!(:new_klass) { test_klass index_name: new_index_name, attributes: [:foo] }
|
9
10
|
|
10
11
|
let(:test_post) { original_klass.create id: 1, text: 'test_post' }
|
11
12
|
|
13
|
+
let(:elastic_client) { Elasticsearch::Client.new(host: ES_HOST, log: false) }
|
14
|
+
let(:alias_index) { elastic_client.indices.put_alias(index: orig_index_name, name: orig_index_alias) }
|
15
|
+
|
12
16
|
# Create the index (test_index) on the test_klass:
|
13
17
|
before do
|
14
18
|
original_klass.create_index!
|
@@ -16,13 +20,14 @@ describe "reindex!", type: :integration do
|
|
16
20
|
original_klass.refresh_index!
|
17
21
|
end
|
18
22
|
|
19
|
-
let(:reindexed_post)
|
23
|
+
let(:reindexed_post) { new_klass.find test_post.id }
|
20
24
|
|
21
|
-
let(:reindex)
|
22
|
-
let(:
|
23
|
-
let(:
|
24
|
-
let(:
|
25
|
-
let(:
|
25
|
+
let(:reindex) { ESReindex.reindex! "#{ES_HOST}/#{orig_index_name}", "#{ES_HOST}/#{new_index_name}", opts }
|
26
|
+
let(:aliased_reindex) { ESReindex.reindex! "#{ES_HOST}/#{orig_index_alias}", "#{ES_HOST}/#{new_index_name}", opts }
|
27
|
+
let(:mappings) { ->{ new_klass.mappings } }
|
28
|
+
let(:settings) { ->{ new_klass.settings } }
|
29
|
+
let(:other_opts) { {} }
|
30
|
+
let(:opts) { {mappings: mappings, settings: settings}.merge other_opts }
|
26
31
|
|
27
32
|
it "reindexes with the selected mappings" do
|
28
33
|
reindex
|
@@ -32,6 +37,16 @@ describe "reindex!", type: :integration do
|
|
32
37
|
expect(reindexed_post).to respond_to :foo
|
33
38
|
end
|
34
39
|
|
40
|
+
it "reindexes alias with the selected mappings" do
|
41
|
+
alias_index
|
42
|
+
|
43
|
+
aliased_reindex
|
44
|
+
|
45
|
+
expect(reindexed_post.id).to eq test_post.id
|
46
|
+
expect(reindexed_post.text).to eq test_post.text
|
47
|
+
expect(reindexed_post).to respond_to :foo
|
48
|
+
end
|
49
|
+
|
35
50
|
context "with a :unless guard" do
|
36
51
|
let(:other_opts) do
|
37
52
|
{
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es-reindex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Aiken
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-02-
|
12
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: elasticsearch
|
@@ -25,20 +25,6 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 1.0.0
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: activesupport
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
35
|
-
type: :runtime
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
42
28
|
- !ruby/object:Gem::Dependency
|
43
29
|
name: elasticsearch-persistence
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|