elasticsearch-indexstager 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/elasticsearch/index_stager.rb +34 -8
- metadata +13 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76c39583b931131ea4295d5e688576aafb1bddd0
|
4
|
+
data.tar.gz: fd11d8330619935de3806c9d3428d096723a2dd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74a48322315750170369c4f8559cfb547b2661615033573c57a214ef89f757b56601e639209bab2605240d44723d925e5adb4c44390f912ad33135d5b248f091
|
7
|
+
data.tar.gz: c719ff554f84b1f80e01ce7591394521f00d78fafc08491e48b4d3a62b8682568433b865c62decf51725dbd7c2f4a90959b82812d2c350c1d1254363f3262b2b
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# elasticsearch-indexstager RubyGem
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/
|
3
|
+
[![Build Status](https://travis-ci.org/karpet/elasticsearch-indexstager-gem.svg?branch=master)](https://travis-ci.org/karpet/elasticsearch-indexstager-gem)
|
4
4
|
|
5
5
|
Elasticsearch index management, for stage/promote pattern.
|
6
6
|
|
7
7
|
See also:
|
8
8
|
|
9
|
-
* [elasticsearch-rails-ha](https://github.com/
|
9
|
+
* [elasticsearch-rails-ha](https://github.com/karpet/elasticsearch-rails-ha)
|
10
10
|
|
11
11
|
## Examples
|
12
12
|
|
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
module Elasticsearch
|
2
4
|
class IndexStager
|
3
|
-
VERSION = '1.
|
5
|
+
VERSION = '1.1.0'
|
4
6
|
|
5
7
|
attr_reader :index_name, :es_client
|
6
8
|
|
@@ -33,13 +35,21 @@ module Elasticsearch
|
|
33
35
|
# the renaming actions (performed atomically by ES)
|
34
36
|
rename_actions = [
|
35
37
|
{ remove: { index: stage_aliased_to, alias: stage_index_name } },
|
36
|
-
{ add: { index:
|
38
|
+
{ add: { index: stage_aliased_to, alias: @live_index_name } }
|
37
39
|
]
|
38
40
|
|
39
41
|
# zap any existing index known as index_name,
|
40
42
|
# but do it conditionally since it is reasonable that it does not exist.
|
41
43
|
to_delete = []
|
42
|
-
|
44
|
+
live_index_exists = false
|
45
|
+
begin
|
46
|
+
existing_live_index = es_client.indices.get_alias(index: @live_index_name, name: '*')
|
47
|
+
live_index_exists = true
|
48
|
+
rescue Elasticsearch::Transport::Transport::Errors::NotFound => _err
|
49
|
+
existing_live_index = {}
|
50
|
+
rescue => _err
|
51
|
+
raise _err
|
52
|
+
end
|
43
53
|
existing_live_index.each do |k,v|
|
44
54
|
|
45
55
|
# if the index is merely aliased, remove its alias as part of the aliasing transaction.
|
@@ -50,11 +60,27 @@ module Elasticsearch
|
|
50
60
|
to_delete.push k
|
51
61
|
|
52
62
|
else
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
63
|
+
raise "Found existing index called #{@live_index_name} aliased to itself"
|
64
|
+
end
|
65
|
+
end
|
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)
|
57
80
|
end
|
81
|
+
|
82
|
+
# delete the original
|
83
|
+
es_client.indices.delete index: @live_index_name rescue false
|
58
84
|
end
|
59
85
|
|
60
86
|
# re-alias
|
@@ -80,7 +106,7 @@ module Elasticsearch
|
|
80
106
|
|
81
107
|
def find_newest_alias_for(the_index_name)
|
82
108
|
aliased_to = nil
|
83
|
-
aliases = es_client.indices.
|
109
|
+
aliases = es_client.indices.get_alias(index: the_index_name, name: '*')
|
84
110
|
aliases.each do |k,v|
|
85
111
|
next unless k.match(tmp_index_pattern)
|
86
112
|
aliased_to ||= k
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-indexstager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Karman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: about_yml
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
24
|
+
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
26
|
+
version: '6.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,28 +42,28 @@ dependencies:
|
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
47
|
version: '0'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - "
|
52
|
+
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rspec
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - "
|
59
|
+
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
61
|
version: '0'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
@@ -96,7 +82,7 @@ dependencies:
|
|
96
82
|
version: '0'
|
97
83
|
description: manage Elasticsearch indexes using staging pattern
|
98
84
|
email:
|
99
|
-
-
|
85
|
+
- karpet@peknet.com
|
100
86
|
executables: []
|
101
87
|
extensions: []
|
102
88
|
extra_rdoc_files: []
|
@@ -105,7 +91,7 @@ files:
|
|
105
91
|
- LICENSE.md
|
106
92
|
- README.md
|
107
93
|
- lib/elasticsearch/index_stager.rb
|
108
|
-
homepage: https://github.com/
|
94
|
+
homepage: https://github.com/karpet/elasticsearch-indexstager-gem
|
109
95
|
licenses:
|
110
96
|
- CC0
|
111
97
|
metadata: {}
|
@@ -125,9 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
111
|
version: '0'
|
126
112
|
requirements: []
|
127
113
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.6.13
|
129
115
|
signing_key:
|
130
116
|
specification_version: 4
|
131
117
|
summary: manage Elasticsearch indexes using staging pattern
|
132
118
|
test_files: []
|
133
|
-
has_rdoc:
|