esse 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/esse/cli/event_listener.rb +4 -5
- data/lib/esse/cli/generate.rb +14 -16
- data/lib/esse/cli/index/close.rb +1 -1
- data/lib/esse/cli/index/create.rb +1 -1
- data/lib/esse/cli/index/delete.rb +1 -1
- data/lib/esse/cli/index/import.rb +2 -2
- data/lib/esse/cli/index/open.rb +1 -1
- data/lib/esse/cli/index/reset.rb +1 -1
- data/lib/esse/cli/index/update_aliases.rb +2 -2
- data/lib/esse/cli/index/update_mapping.rb +8 -3
- data/lib/esse/cli/index/update_settings.rb +1 -1
- data/lib/esse/cli/index.rb +9 -4
- data/lib/esse/cli/templates/collection.rb.erb +6 -6
- data/lib/esse/cli/templates/{serializer.rb.erb → document.rb.erb} +6 -6
- data/lib/esse/cli/templates/index.rb.erb +39 -34
- data/lib/esse/cli.rb +5 -0
- data/lib/esse/cluster.rb +38 -12
- data/lib/esse/core.rb +7 -3
- data/lib/esse/deprecations/cluster.rb +5 -5
- data/lib/esse/deprecations/deprecate.rb +29 -0
- data/lib/esse/deprecations/index.rb +21 -3
- data/lib/esse/deprecations/index_backend_delegator.rb +217 -0
- data/lib/esse/deprecations/repository.rb +19 -4
- data/lib/esse/deprecations/repository_backend_delegator.rb +110 -0
- data/lib/esse/deprecations/serializer.rb +14 -0
- data/lib/esse/deprecations.rb +4 -0
- data/lib/esse/{serializer.rb → document.rb} +17 -2
- data/lib/esse/dynamic_template.rb +4 -0
- data/lib/esse/errors.rb +8 -1
- data/lib/esse/events.rb +13 -5
- data/lib/esse/hash_document.rb +1 -1
- data/lib/esse/import/bulk.rb +21 -11
- data/lib/esse/index/aliases.rb +50 -0
- data/lib/esse/index/attributes.rb +14 -5
- data/lib/esse/index/base.rb +17 -53
- data/lib/esse/index/documents.rb +236 -0
- data/lib/esse/index/indices.rb +171 -0
- data/lib/esse/index/object_document_mapper.rb +0 -59
- data/lib/esse/index/type.rb +2 -3
- data/lib/esse/index.rb +4 -3
- data/lib/esse/null_document.rb +1 -1
- data/lib/esse/repository/{backend.rb → documents.rb} +2 -3
- data/lib/esse/repository/object_document_mapper.rb +20 -20
- data/lib/esse/repository.rb +1 -2
- data/lib/esse/search/query.rb +8 -8
- data/lib/esse/template_loader.rb +1 -1
- data/lib/esse/transport/aliases.rb +36 -0
- data/lib/esse/transport/documents.rb +199 -0
- data/lib/esse/transport/health.rb +30 -0
- data/lib/esse/transport/indices.rb +192 -0
- data/lib/esse/{client_proxy → transport}/search.rb +9 -5
- data/lib/esse/transport.rb +44 -0
- data/lib/esse/version.rb +1 -1
- metadata +28 -28
- data/lib/esse/backend/index/aliases.rb +0 -73
- data/lib/esse/backend/index/close.rb +0 -54
- data/lib/esse/backend/index/create.rb +0 -67
- data/lib/esse/backend/index/delete.rb +0 -39
- data/lib/esse/backend/index/documents.rb +0 -270
- data/lib/esse/backend/index/existance.rb +0 -22
- data/lib/esse/backend/index/open.rb +0 -54
- data/lib/esse/backend/index/refresh.rb +0 -45
- data/lib/esse/backend/index/reset.rb +0 -33
- data/lib/esse/backend/index/update.rb +0 -143
- data/lib/esse/backend/index.rb +0 -56
- data/lib/esse/backend/repository_backend.rb +0 -105
- data/lib/esse/client_proxy.rb +0 -32
- data/lib/esse/index/backend.rb +0 -14
@@ -3,17 +3,35 @@
|
|
3
3
|
module Esse
|
4
4
|
class Index
|
5
5
|
class << self
|
6
|
-
extend
|
6
|
+
extend Esse::Deprecations::Deprecate
|
7
7
|
|
8
8
|
def define_type(name, *args, **kwargs, &block)
|
9
9
|
repository(name, *args, **kwargs, &block)
|
10
10
|
end
|
11
|
-
deprecate :define_type, :repository,
|
11
|
+
deprecate :define_type, :repository, 2023, 12
|
12
12
|
|
13
13
|
def type_hash
|
14
14
|
repo_hash
|
15
15
|
end
|
16
|
-
deprecate :type_hash, :repo_hash,
|
16
|
+
deprecate :type_hash, :repo_hash, 2023, 12
|
17
|
+
|
18
|
+
def index_version
|
19
|
+
index_suffix
|
20
|
+
end
|
21
|
+
deprecate :index_version, :index_suffix, 2023, 12
|
22
|
+
|
23
|
+
def index_version=(value)
|
24
|
+
self.index_suffix = value
|
25
|
+
end
|
26
|
+
deprecate :index_version=, :index_suffix=, 2023, 12
|
27
|
+
|
28
|
+
def elasticsearch
|
29
|
+
Esse::Deprecations::IndexBackendDelegator.new(:elasticsearch, self)
|
30
|
+
end
|
31
|
+
|
32
|
+
def backend
|
33
|
+
Esse::Deprecations::IndexBackendDelegator.new(:backend, self)
|
34
|
+
end
|
17
35
|
end
|
18
36
|
end
|
19
37
|
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
module Deprecations
|
5
|
+
class IndexBackendDelegator
|
6
|
+
extend Esse::Deprecations::Deprecate
|
7
|
+
|
8
|
+
def initialize(namespace, index)
|
9
|
+
@namespace = namespace
|
10
|
+
@index = index
|
11
|
+
end
|
12
|
+
|
13
|
+
def aliases(**kwargs)
|
14
|
+
warning("#{@index}.#{@namespace}.aliases", "#{@index}.aliases", 2023, 12)
|
15
|
+
@index.aliases(**kwargs)
|
16
|
+
end
|
17
|
+
|
18
|
+
def indices(**kwargs)
|
19
|
+
warning("#{@index}.#{@namespace}.indices", "#{@index}.indices_pointing_to_alias", 2023, 12)
|
20
|
+
@index.indices_pointing_to_alias(**kwargs)
|
21
|
+
end
|
22
|
+
|
23
|
+
def update_aliases!(**kwargs)
|
24
|
+
warning("#{@index}.#{@namespace}.update_aliases!", "#{@index}.update_aliases", 2023, 12)
|
25
|
+
@index.update_aliases(**kwargs)
|
26
|
+
end
|
27
|
+
|
28
|
+
def update_aliases(**kwargs)
|
29
|
+
warning("#{@index}.#{@namespace}.update_aliases", "#{@index}.update_aliases", 2023, 12)
|
30
|
+
|
31
|
+
@index.update_aliases(**kwargs)
|
32
|
+
rescue Esse::Transport::NotFoundError
|
33
|
+
{ 'errors' => true }
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_index(**kwargs)
|
37
|
+
warning("#{@index}.#{@namespace}.create_index", "#{@index}.create_index", 2023, 12)
|
38
|
+
|
39
|
+
@index.create_index(**kwargs)
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_index!(**kwargs)
|
43
|
+
warning("#{@index}.#{@namespace}.create_index!", "#{@index}.create_index", 2023, 12)
|
44
|
+
|
45
|
+
@index.create_index(**kwargs)
|
46
|
+
end
|
47
|
+
|
48
|
+
def close(**kwargs)
|
49
|
+
warning("#{@index}.#{@namespace}.close", "#{@index}.close", 2023, 12)
|
50
|
+
|
51
|
+
@index.close(**kwargs)
|
52
|
+
end
|
53
|
+
|
54
|
+
def close!(**kwargs)
|
55
|
+
warning("#{@index}.#{@namespace}.close!", "#{@index}.close", 2023, 12)
|
56
|
+
|
57
|
+
@index.close(**kwargs)
|
58
|
+
end
|
59
|
+
|
60
|
+
def open(**kwargs)
|
61
|
+
warning("#{@index}.#{@namespace}.open", "#{@index}.open", 2023, 12)
|
62
|
+
|
63
|
+
@index.open(**kwargs)
|
64
|
+
end
|
65
|
+
|
66
|
+
def open!(**kwargs)
|
67
|
+
warning("#{@index}.#{@namespace}.open!", "#{@index}.open", 2023, 12)
|
68
|
+
|
69
|
+
@index.open(**kwargs)
|
70
|
+
end
|
71
|
+
|
72
|
+
def refresh(**kwargs)
|
73
|
+
warning("#{@index}.#{@namespace}.refresh", "#{@index}.refresh", 2023, 12)
|
74
|
+
|
75
|
+
@index.refresh(**kwargs)
|
76
|
+
end
|
77
|
+
|
78
|
+
def refresh!(**kwargs)
|
79
|
+
warning("#{@index}.#{@namespace}.refresh!", "#{@index}.refresh", 2023, 12)
|
80
|
+
|
81
|
+
@index.refresh(**kwargs)
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete_index(**kwargs)
|
85
|
+
warning("#{@index}.#{@namespace}.delete_index", "#{@index}.delete_index", 2023, 12)
|
86
|
+
|
87
|
+
@index.delete_index(**kwargs)
|
88
|
+
end
|
89
|
+
|
90
|
+
def delete_index!(**kwargs)
|
91
|
+
warning("#{@index}.#{@namespace}.delete_index!", "#{@index}.delete_index", 2023, 12)
|
92
|
+
|
93
|
+
@index.delete_index(**kwargs)
|
94
|
+
end
|
95
|
+
|
96
|
+
def index_exist?(**kwargs)
|
97
|
+
warning("#{@index}.#{@namespace}.index_exist?", "#{@index}.index_exist?", 2023, 12)
|
98
|
+
|
99
|
+
@index.index_exist?(**kwargs)
|
100
|
+
end
|
101
|
+
|
102
|
+
def update_mapping!(**kwargs)
|
103
|
+
warning("#{@index}.#{@namespace}.update_mapping!", "#{@index}.update_mapping", 2023, 12)
|
104
|
+
|
105
|
+
@index.update_mapping(**kwargs)
|
106
|
+
end
|
107
|
+
|
108
|
+
def update_mapping(**kwargs)
|
109
|
+
warning("#{@index}.#{@namespace}.update_mapping", "#{@index}.update_mapping", 2023, 12)
|
110
|
+
|
111
|
+
@index.update_mapping(**kwargs)
|
112
|
+
end
|
113
|
+
|
114
|
+
def update_settings!(**kwargs)
|
115
|
+
warning("#{@index}.#{@namespace}.update_settings!", "#{@index}.update_settings", 2023, 12)
|
116
|
+
|
117
|
+
@index.update_settings(**kwargs)
|
118
|
+
end
|
119
|
+
|
120
|
+
def update_settings(**kwargs)
|
121
|
+
warning("#{@index}.#{@namespace}.update_settings", "#{@index}.update_settings", 2023, 12)
|
122
|
+
|
123
|
+
@index.update_settings(**kwargs)
|
124
|
+
end
|
125
|
+
|
126
|
+
def reset_index!(**kwargs)
|
127
|
+
warning("#{@index}.#{@namespace}.reset_index!", "#{@index}.reset_index", 2023, 12)
|
128
|
+
|
129
|
+
@index.reset_index(**kwargs)
|
130
|
+
end
|
131
|
+
|
132
|
+
def import(**kwargs)
|
133
|
+
warning("#{@index}.#{@namespace}.import", "#{@index}.import", 2023, 12)
|
134
|
+
|
135
|
+
@index.import(**kwargs)
|
136
|
+
end
|
137
|
+
|
138
|
+
def import!(**kwargs)
|
139
|
+
warning("#{@index}.#{@namespace}.import!", "#{@index}.import", 2023, 12)
|
140
|
+
|
141
|
+
@index.import(**kwargs)
|
142
|
+
end
|
143
|
+
|
144
|
+
def bulk!(**kwargs)
|
145
|
+
warning("#{@index}.#{@namespace}.bulk!", "#{@index}.bulk", 2023, 12)
|
146
|
+
|
147
|
+
@index.bulk(**kwargs)
|
148
|
+
end
|
149
|
+
|
150
|
+
def bulk(**kwargs)
|
151
|
+
warning("#{@index}.#{@namespace}.bulk", "#{@index}.bulk", 2023, 12)
|
152
|
+
|
153
|
+
@index.bulk(**kwargs)
|
154
|
+
end
|
155
|
+
|
156
|
+
def index!(**kwargs)
|
157
|
+
warning("#{@index}.#{@namespace}.index!", "#{@index}.index", 2023, 12)
|
158
|
+
|
159
|
+
@index.index(**kwargs)
|
160
|
+
end
|
161
|
+
|
162
|
+
def index(**kwargs)
|
163
|
+
warning("#{@index}.#{@namespace}.index", "#{@index}.index", 2023, 12)
|
164
|
+
|
165
|
+
@index.index(**kwargs)
|
166
|
+
end
|
167
|
+
|
168
|
+
def update!(**kwargs)
|
169
|
+
warning("#{@index}.#{@namespace}.update!", "#{@index}.update", 2023, 12)
|
170
|
+
|
171
|
+
@index.update(**kwargs)
|
172
|
+
end
|
173
|
+
|
174
|
+
def update(**kwargs)
|
175
|
+
warning("#{@index}.#{@namespace}.update", "#{@index}.update", 2023, 12)
|
176
|
+
|
177
|
+
@index.update(**kwargs)
|
178
|
+
end
|
179
|
+
|
180
|
+
def delete!(**kwargs)
|
181
|
+
warning("#{@index}.#{@namespace}.delete!", "#{@index}.delete", 2023, 12)
|
182
|
+
|
183
|
+
@index.delete(**kwargs)
|
184
|
+
end
|
185
|
+
|
186
|
+
def delete(**kwargs)
|
187
|
+
warning("#{@index}.#{@namespace}.delete", "#{@index}.delete", 2023, 12)
|
188
|
+
|
189
|
+
@index.delete(**kwargs)
|
190
|
+
end
|
191
|
+
|
192
|
+
def count(**kwargs)
|
193
|
+
warning("#{@index}.#{@namespace}.count", "#{@index}.count", 2023, 12)
|
194
|
+
|
195
|
+
@index.count(**kwargs)
|
196
|
+
end
|
197
|
+
|
198
|
+
def exist?(**kwargs)
|
199
|
+
warning("#{@index}.#{@namespace}.exist?", "#{@index}.exist?", 2023, 12)
|
200
|
+
|
201
|
+
@index.exist?(**kwargs)
|
202
|
+
end
|
203
|
+
|
204
|
+
def find!(**kwargs)
|
205
|
+
warning("#{@index}.#{@namespace}.find!", "#{@index}.get", 2023, 12)
|
206
|
+
|
207
|
+
@index.get(**kwargs)
|
208
|
+
end
|
209
|
+
|
210
|
+
def find(**kwargs)
|
211
|
+
warning("#{@index}.#{@namespace}.find", "#{@index}.get", 2023, 12)
|
212
|
+
|
213
|
+
@index.get(**kwargs)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
@@ -3,17 +3,32 @@
|
|
3
3
|
module Esse
|
4
4
|
class Repository
|
5
5
|
class << self
|
6
|
-
extend
|
6
|
+
extend Esse::Deprecations::Deprecate
|
7
7
|
|
8
8
|
def type_name
|
9
|
-
|
9
|
+
repo_name
|
10
10
|
end
|
11
|
-
deprecate :type_name, :
|
11
|
+
deprecate :type_name, :repo_type, 2023, 12
|
12
12
|
|
13
13
|
def mappings(*args, &block)
|
14
|
+
warning("#{self}.mappings", "#{index}.mappings", 2023, 12)
|
15
|
+
|
14
16
|
index.mappings(*args, &block)
|
15
17
|
end
|
16
|
-
|
18
|
+
|
19
|
+
def serializer(*args, **kwargs, &block)
|
20
|
+
warning("#{self}.serializer", "#{self}.document", 2023, 12)
|
21
|
+
|
22
|
+
document(*args, **kwargs, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def elasticsearch
|
26
|
+
Esse::Deprecations::RepositoryBackendDelegator.new(:elasticsearch, self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def backend
|
30
|
+
Esse::Deprecations::RepositoryBackendDelegator.new(:backend, self)
|
31
|
+
end
|
17
32
|
end
|
18
33
|
end
|
19
34
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
module Deprecations
|
5
|
+
class RepositoryBackendDelegator
|
6
|
+
extend Esse::Deprecations::Deprecate
|
7
|
+
|
8
|
+
def initialize(namespace, repo)
|
9
|
+
@namespace = namespace
|
10
|
+
@repo = repo
|
11
|
+
end
|
12
|
+
|
13
|
+
def import(**kwargs)
|
14
|
+
warning("#{@repo}.#{@namespace}.import", "#{@repo}.import", 2023, 12)
|
15
|
+
|
16
|
+
@repo.import(**kwargs)
|
17
|
+
end
|
18
|
+
|
19
|
+
def import!(**kwargs)
|
20
|
+
warning("#{@repo}.#{@namespace}.import!", "#{@repo}.import", 2023, 12)
|
21
|
+
|
22
|
+
@repo.import(**kwargs)
|
23
|
+
end
|
24
|
+
|
25
|
+
def bulk(**kwargs)
|
26
|
+
warning("#{@repo}.#{@namespace}.bulk", "#{@repo.index}.bulk", 2023, 12)
|
27
|
+
|
28
|
+
@repo.index.bulk(**kwargs)
|
29
|
+
end
|
30
|
+
|
31
|
+
def bulk!(**kwargs)
|
32
|
+
warning("#{@repo}.#{@namespace}.bulk!", "#{@repo.index}.bulk", 2023, 12)
|
33
|
+
|
34
|
+
@repo.index.bulk(**kwargs)
|
35
|
+
end
|
36
|
+
|
37
|
+
def index(**kwargs)
|
38
|
+
warning("#{@repo}.#{@namespace}.index", "#{@repo.index}.index", 2023, 12)
|
39
|
+
|
40
|
+
@repo.index.index(**kwargs)
|
41
|
+
end
|
42
|
+
|
43
|
+
def index!(**kwargs)
|
44
|
+
warning("#{@repo}.#{@namespace}.index!", "#{@repo.index}.index", 2023, 12)
|
45
|
+
|
46
|
+
@repo.index.index(**kwargs)
|
47
|
+
end
|
48
|
+
|
49
|
+
def index_document(*args, **kwargs)
|
50
|
+
warning("#{@repo}.#{@namespace}.index_document", "#{@repo.index}.index", 2023, 12)
|
51
|
+
|
52
|
+
@repo.index.index(*args, **kwargs)
|
53
|
+
end
|
54
|
+
|
55
|
+
def update!(**kwargs)
|
56
|
+
warning("#{@repo}.#{@namespace}.update!", "#{@repo.index}.update", 2023, 12)
|
57
|
+
|
58
|
+
@repo.index.update(**kwargs)
|
59
|
+
end
|
60
|
+
|
61
|
+
def update(**kwargs)
|
62
|
+
warning("#{@repo}.#{@namespace}.update", "#{@repo.index}.update", 2023, 12)
|
63
|
+
|
64
|
+
@repo.index.update(**kwargs)
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete!(**kwargs)
|
68
|
+
warning("#{@repo}.#{@namespace}.delete!", "#{@repo.index}.delete", 2023, 12)
|
69
|
+
|
70
|
+
@repo.index.delete(**kwargs)
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete(**kwargs)
|
74
|
+
warning("#{@repo}.#{@namespace}.delete", "#{@repo.index}.delete", 2023, 12)
|
75
|
+
|
76
|
+
@repo.index.delete(**kwargs)
|
77
|
+
end
|
78
|
+
|
79
|
+
def delete_document(*args, **kwargs)
|
80
|
+
warning("#{@repo}.#{@namespace}.delete_document", "#{@repo.index}.delete", 2023, 12)
|
81
|
+
|
82
|
+
@repo.index.delete(*args, **kwargs)
|
83
|
+
end
|
84
|
+
|
85
|
+
def count(**kwargs)
|
86
|
+
warning("#{@repo}.#{@namespace}.count", "#{@repo.index}.count", 2023, 12)
|
87
|
+
|
88
|
+
@repo.index.count(**kwargs)
|
89
|
+
end
|
90
|
+
|
91
|
+
def exist?(**kwargs)
|
92
|
+
warning("#{@repo}.#{@namespace}.exist?", "#{@repo.index}.exist?", 2023, 12)
|
93
|
+
|
94
|
+
@repo.index.exist?(**kwargs)
|
95
|
+
end
|
96
|
+
|
97
|
+
def find!(**kwargs)
|
98
|
+
warning("#{@repo}.#{@namespace}.find!", "#{@repo.index}.get", 2023, 12)
|
99
|
+
|
100
|
+
@repo.index.get(**kwargs)
|
101
|
+
end
|
102
|
+
|
103
|
+
def find(**kwargs)
|
104
|
+
warning("#{@repo}.#{@namespace}.find", "#{@repo.index}.get", 2023, 12)
|
105
|
+
|
106
|
+
@repo.index.get(**kwargs)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
class Serializer < Esse::Document
|
5
|
+
class << self
|
6
|
+
extend Esse::Deprecations::Deprecate
|
7
|
+
|
8
|
+
def inherited(subclass)
|
9
|
+
warning 'Esse::Serializer', 'Esse::Document', 2023, 12
|
10
|
+
super(subclass)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/esse/deprecations.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require_relative 'deprecations/deprecate'
|
2
|
+
require_relative 'deprecations/serializer'
|
3
|
+
require_relative 'deprecations/index_backend_delegator'
|
1
4
|
require_relative 'deprecations/index'
|
2
5
|
require_relative 'deprecations/cluster'
|
6
|
+
require_relative 'deprecations/repository_backend_delegator'
|
3
7
|
require_relative 'deprecations/repository'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Esse
|
4
|
-
class
|
4
|
+
class Document
|
5
5
|
attr_reader :object, :options
|
6
6
|
|
7
7
|
def initialize(object, **options)
|
@@ -21,12 +21,27 @@ module Esse
|
|
21
21
|
nil
|
22
22
|
end
|
23
23
|
|
24
|
+
# @return [Boolean] whether the document has type
|
25
|
+
def type?
|
26
|
+
!type.nil?
|
27
|
+
end
|
28
|
+
|
24
29
|
# @return [String, nil] the document routing
|
25
30
|
# @abstract Override this method to return the document routing
|
26
31
|
def routing
|
27
32
|
nil
|
28
33
|
end
|
29
34
|
|
35
|
+
# @return [Boolean] whether the document has routing
|
36
|
+
def routing?
|
37
|
+
!routing.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
# @TODO allow import, index, bulk to accept a suffix to tell which index to use
|
41
|
+
# def index_suffix
|
42
|
+
# nil
|
43
|
+
# end
|
44
|
+
|
30
45
|
# @return [Hash] the document meta
|
31
46
|
# @abstract Override this method to return the document meta
|
32
47
|
def meta
|
@@ -54,7 +69,7 @@ module Esse
|
|
54
69
|
{ _id: id }.tap do |h|
|
55
70
|
h[:data] = source&.to_h if data
|
56
71
|
h[:_type] = type if type
|
57
|
-
h[:routing] = routing if routing
|
72
|
+
h[:routing] = routing if routing?
|
58
73
|
h.merge!(meta)
|
59
74
|
end
|
60
75
|
end
|
data/lib/esse/errors.rb
CHANGED
@@ -5,9 +5,16 @@ module Esse
|
|
5
5
|
end
|
6
6
|
|
7
7
|
# @todo Rename this
|
8
|
-
|
8
|
+
class Transport
|
9
9
|
class ServerError < ::Esse::Error; end
|
10
10
|
|
11
|
+
# exception to raise when the cluster is readonly
|
12
|
+
class ReadonlyClusterError < ::Esse::Error
|
13
|
+
def initialize
|
14
|
+
super('You cannot perform this operation on a readonly cluster')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
11
18
|
ES_TRANSPORT_ERRORS = {
|
12
19
|
'MultipleChoices' => 'MultipleChoicesError', # 300
|
13
20
|
'MovedPermanently' => 'MovedPermanentlyError', # 301
|
data/lib/esse/events.rb
CHANGED
@@ -38,15 +38,23 @@ module Esse
|
|
38
38
|
module Events
|
39
39
|
include Publisher
|
40
40
|
|
41
|
+
register_event 'elasticsearch.bulk'
|
41
42
|
register_event 'elasticsearch.close'
|
42
|
-
register_event 'elasticsearch.open'
|
43
43
|
register_event 'elasticsearch.create_index'
|
44
44
|
register_event 'elasticsearch.delete_index'
|
45
|
+
register_event 'elasticsearch.execute_search_query'
|
46
|
+
register_event 'elasticsearch.index_exist'
|
47
|
+
register_event 'elasticsearch.open'
|
48
|
+
register_event 'elasticsearch.refresh'
|
49
|
+
register_event 'elasticsearch.search'
|
50
|
+
register_event 'elasticsearch.update_aliases'
|
45
51
|
register_event 'elasticsearch.update_mapping'
|
46
52
|
register_event 'elasticsearch.update_settings'
|
47
|
-
register_event 'elasticsearch.
|
48
|
-
register_event 'elasticsearch.
|
49
|
-
register_event 'elasticsearch.
|
50
|
-
register_event 'elasticsearch.
|
53
|
+
register_event 'elasticsearch.index'
|
54
|
+
register_event 'elasticsearch.update'
|
55
|
+
register_event 'elasticsearch.delete'
|
56
|
+
register_event 'elasticsearch.exist'
|
57
|
+
register_event 'elasticsearch.count'
|
58
|
+
register_event 'elasticsearch.get'
|
51
59
|
end
|
52
60
|
end
|
data/lib/esse/hash_document.rb
CHANGED
data/lib/esse/import/bulk.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
module Esse
|
2
2
|
module Import
|
3
3
|
class Bulk
|
4
|
-
def initialize(index: nil, delete: nil, create: nil)
|
4
|
+
def initialize(type: nil, index: nil, delete: nil, create: nil)
|
5
5
|
@index = Array(index).select(&method(:valid_doc?)).reject(&:ignore_on_index?).map do |doc|
|
6
|
-
|
6
|
+
value = doc.to_bulk
|
7
|
+
value[:_type] ||= type if type
|
8
|
+
{ index: value }
|
7
9
|
end
|
8
10
|
@create = Array(create).select(&method(:valid_doc?)).reject(&:ignore_on_index?).map do |doc|
|
9
|
-
|
11
|
+
value = doc.to_bulk
|
12
|
+
value[:_type] ||= type if type
|
13
|
+
{ create: value }
|
10
14
|
end
|
11
15
|
@delete = Array(delete).select(&method(:valid_doc?)).reject(&:ignore_on_delete?).map do |doc|
|
12
|
-
|
16
|
+
value = doc.to_bulk(data: false)
|
17
|
+
value[:_type] ||= type if type
|
18
|
+
{ delete: value }
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
@@ -22,26 +28,31 @@ module Esse
|
|
22
28
|
#
|
23
29
|
# @yield [RequestBody] A request body instance
|
24
30
|
def each_request(max_retries: 3)
|
31
|
+
# @TODO create indexes when by checking all the index suffixes (if mapping is not empty)
|
25
32
|
requests = [optimistic_request]
|
26
33
|
retry_count = 0
|
27
34
|
|
28
35
|
begin
|
29
36
|
requests.each do |request|
|
30
|
-
|
37
|
+
next unless request.body?
|
38
|
+
resp = yield request
|
39
|
+
if resp&.[]('errors')
|
40
|
+
raise resp&.fetch('items', [])&.select { |item| item.values.first['error'] }&.join("\n")
|
41
|
+
end
|
31
42
|
end
|
32
|
-
rescue Faraday::TimeoutError, Esse::
|
43
|
+
rescue Faraday::TimeoutError, Esse::Transport::RequestTimeoutError => e
|
33
44
|
retry_count += 1
|
34
|
-
raise Esse::
|
45
|
+
raise Esse::Transport::RequestTimeoutError.new(e.message) if retry_count >= max_retries
|
35
46
|
wait_interval = (retry_count**4) + 15 + (rand(10) * (retry_count + 1))
|
36
47
|
Esse.logger.warn "Timeout error, retrying in #{wait_interval} seconds"
|
37
48
|
sleep(wait_interval)
|
38
49
|
retry
|
39
|
-
rescue Esse::
|
50
|
+
rescue Esse::Transport::RequestEntityTooLargeError => e
|
40
51
|
retry_count += 1
|
41
52
|
raise e if retry_count > 1 # only retry once on this error
|
42
53
|
requests = balance_requests_size(e)
|
43
54
|
Esse.logger.warn <<~MSG
|
44
|
-
Request entity too large, retrying with a bulk with: #{requests.map(&:bytesize).join(
|
55
|
+
Request entity too large, retrying with a bulk with: #{requests.map(&:bytesize).join(' + ')}.
|
45
56
|
Note that this cause performance degradation, consider adjusting the batch_size of the index or increasing the bulk size.
|
46
57
|
MSG
|
47
58
|
retry
|
@@ -51,7 +62,7 @@ module Esse
|
|
51
62
|
private
|
52
63
|
|
53
64
|
def valid_doc?(doc)
|
54
|
-
|
65
|
+
Esse.document?(doc)
|
55
66
|
end
|
56
67
|
|
57
68
|
def optimistic_request
|
@@ -90,7 +101,6 @@ module Esse
|
|
90
101
|
raise err
|
91
102
|
end
|
92
103
|
end
|
93
|
-
|
94
104
|
end
|
95
105
|
end
|
96
106
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
class Index
|
5
|
+
module ClassMethods
|
6
|
+
# Get the aliases for the index.
|
7
|
+
def aliases(**options)
|
8
|
+
response = cluster.api.aliases(**options, index: index_name, name: '*')
|
9
|
+
idx_name = response.keys.find { |idx| idx.start_with?(index_name) }
|
10
|
+
return [] unless idx_name
|
11
|
+
|
12
|
+
response.dig(idx_name, 'aliases')&.keys || []
|
13
|
+
rescue Esse::Transport::NotFoundError
|
14
|
+
[]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Return list of real index names for the virtual index name(alias)
|
18
|
+
def indices_pointing_to_alias(**options)
|
19
|
+
cluster.api.aliases(**options, name: index_name).keys
|
20
|
+
rescue Esse::Transport::NotFoundError
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
|
24
|
+
# Replaces all existing aliases by the respective suffixed index from argument.
|
25
|
+
#
|
26
|
+
# @param options [Hash] Hash of paramenters that will be passed along to elasticsearch request
|
27
|
+
# @option [Array<String>] :suffix One or more index suffixes to point the alias to.
|
28
|
+
# @raise [Esse::Transport::ServerError] in case of failure
|
29
|
+
# @return [Hash] the elasticsearch response
|
30
|
+
def update_aliases(suffix:, **options)
|
31
|
+
cluster.throw_error_when_readonly!
|
32
|
+
raise(ArgumentError, 'index suffix cannot be nil') if suffix.nil?
|
33
|
+
|
34
|
+
options[:body] = {
|
35
|
+
actions: [
|
36
|
+
*indices_pointing_to_alias.map do |index|
|
37
|
+
{ remove: { index: index, alias: index_name } }
|
38
|
+
end,
|
39
|
+
*Array(suffix).map do |value|
|
40
|
+
{ add: { index: build_real_index_name(value), alias: index_name } }
|
41
|
+
end,
|
42
|
+
],
|
43
|
+
}
|
44
|
+
cluster.api.update_aliases(**options)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
extend ClassMethods
|
49
|
+
end
|
50
|
+
end
|