elasticsearch-indexstager 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elasticsearch/index_stager.rb +34 -19
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e73491d3ba2e305ab074aed57062767b46c29d8
|
4
|
+
data.tar.gz: 3595bc3ba4fcf7f4901a6cac98c94dd5c843cea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9de82f1bc5a545de2a13af08a4330745e504c7f3207f85a538d584a2056f174a39c4c32d9f96faffad9901113c64494c667c73f29ecdf517439ed6c35908de67
|
7
|
+
data.tar.gz: 44df44aa561454f8f94cd96cfbf1d17248a85771ec4ece88441ea799ae90b5e22463b932f919862cb5ca1775ce44dc94f958899bbce159a3d34b2fd5294de8c2
|
@@ -2,7 +2,7 @@ require 'securerandom'
|
|
2
2
|
|
3
3
|
module Elasticsearch
|
4
4
|
class IndexStager
|
5
|
-
VERSION = '1.1.
|
5
|
+
VERSION = '1.1.2'
|
6
6
|
|
7
7
|
attr_reader :index_name, :es_client
|
8
8
|
|
@@ -64,24 +64,7 @@ module Elasticsearch
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
if live_index_exists
|
68
|
-
new_name = @live_index_name + '-pre-staged-original'
|
69
|
-
|
70
|
-
# make a copy
|
71
|
-
es_client.reindex body: { source: { index: @live_index_name }, dest: { index: new_name } }
|
72
|
-
|
73
|
-
# make sure the copy exists before we delete the original
|
74
|
-
tries = 0
|
75
|
-
while( tries < 10 ) do
|
76
|
-
indices = ESHelper.client.indices.get_aliases.keys
|
77
|
-
break if indices.include?(new_name)
|
78
|
-
tries += 1
|
79
|
-
sleep(1)
|
80
|
-
end
|
81
|
-
|
82
|
-
# delete the original
|
83
|
-
es_client.indices.delete index: @live_index_name rescue false
|
84
|
-
end
|
67
|
+
rename_live_index if live_index_exists
|
85
68
|
|
86
69
|
# re-alias
|
87
70
|
es_client.indices.update_aliases body: { actions: rename_actions }
|
@@ -94,6 +77,38 @@ module Elasticsearch
|
|
94
77
|
|
95
78
|
private
|
96
79
|
|
80
|
+
def rename_live_index
|
81
|
+
# if the live index exists but is empty, it fill fail to reindex (rename)
|
82
|
+
# so catch that case and just delete it.
|
83
|
+
idx_stats = es_client.indices.stats index: @live_index_name, docs: true
|
84
|
+
num_docs = idx_stats['indices'][@live_index_name]['total']['docs']['count']
|
85
|
+
if num_docs.to_i == 0
|
86
|
+
es_client.indices.delete index: @live_index_name
|
87
|
+
return
|
88
|
+
end
|
89
|
+
|
90
|
+
new_name = @live_index_name + '-pre-staged-original'
|
91
|
+
renamed = { source: { index: @live_index_name }, dest: { index: new_name } }
|
92
|
+
|
93
|
+
# make a copy
|
94
|
+
es_client.reindex refresh: true, wait_for_completion: true, body: renamed
|
95
|
+
|
96
|
+
# make sure the copy exists before we delete the original
|
97
|
+
tries = 0
|
98
|
+
rename_ok = false
|
99
|
+
while( tries < 10 ) do
|
100
|
+
es_client.indices.refresh index: new_name rescue false
|
101
|
+
indices = es_client.indices.get_aliases.keys
|
102
|
+
break if rename_ok = indices.include?(new_name)
|
103
|
+
tries += 1
|
104
|
+
sleep(1)
|
105
|
+
end
|
106
|
+
raise "Failed to rename #{@live_index_name} -> #{new_name}" unless rename_ok
|
107
|
+
|
108
|
+
# delete the original
|
109
|
+
es_client.indices.delete index: @live_index_name
|
110
|
+
end
|
111
|
+
|
97
112
|
def tmp_index_pattern
|
98
113
|
/#{index_name}_(\d{14})-\w{8}$/
|
99
114
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-indexstager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Karman
|
@@ -44,42 +44,42 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '12.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '3.7'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '3.7'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: elasticsearch-extensions
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '6.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
82
|
+
version: '6.0'
|
83
83
|
description: manage Elasticsearch indexes using staging pattern
|
84
84
|
email:
|
85
85
|
- karpet@peknet.com
|