esse 0.2.2 → 0.2.3
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/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
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Esse
|
4
|
-
class
|
4
|
+
class Transport
|
5
5
|
module InstanceMethods
|
6
6
|
# Returns results matching a query.
|
7
|
+
# @param [Hash] options
|
8
|
+
# @option [String] :index The comma-separated list of index names to search; use `_all` to perform the operation on all indices
|
7
9
|
def search(index:, **options)
|
8
10
|
definition = options.merge(
|
9
11
|
index: index,
|
@@ -17,9 +19,10 @@ module Esse
|
|
17
19
|
|
18
20
|
# Allows to retrieve a large numbers of results from a single search request.
|
19
21
|
#
|
20
|
-
# @param [
|
21
|
-
# @
|
22
|
-
# @
|
22
|
+
# @param [Hash] options
|
23
|
+
# @option [Time] :scroll Specify how long a consistent view of the index should be maintained for scrolled search
|
24
|
+
# @option [Boolean] :rest_total_hits_as_int Indicates whether hits.total should be rendered as an integer or an object in the rest search response
|
25
|
+
# @option [Hash] :body The scroll ID
|
23
26
|
def scroll(scroll:, **definition)
|
24
27
|
unless definition[:body]
|
25
28
|
raise ArgumentError, 'scroll search must have a :body with the :scroll_id'
|
@@ -32,7 +35,8 @@ module Esse
|
|
32
35
|
|
33
36
|
# Explicitly clears the search context for a scroll.
|
34
37
|
#
|
35
|
-
# @param [Hash]
|
38
|
+
# @param [Hash] options
|
39
|
+
# @option [Hash] :body Body with the "scroll_id" (string or array of strings) Scroll IDs to clear.
|
36
40
|
# To clear all scroll IDs, use _all.
|
37
41
|
def clear_scroll(body:, **options)
|
38
42
|
coerce_exception { client.clear_scroll(body: body, **options) }
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
class Transport
|
5
|
+
require_relative './transport/aliases'
|
6
|
+
require_relative './transport/health'
|
7
|
+
require_relative './transport/indices'
|
8
|
+
require_relative './transport/search'
|
9
|
+
require_relative './transport/documents'
|
10
|
+
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
def_delegators :@cluster, :client, :throw_error_when_readonly!
|
14
|
+
|
15
|
+
attr_reader :cluster
|
16
|
+
|
17
|
+
def initialize(cluster)
|
18
|
+
@cluster = cluster
|
19
|
+
end
|
20
|
+
|
21
|
+
# Elasticsearch::Transport was renamed to Elastic::Transport in 8.0
|
22
|
+
# This lib should support both versions that's why we are wrapping up the transport
|
23
|
+
# errors to local errors.
|
24
|
+
#
|
25
|
+
# We are not only coercing exceptions but also the response body. Elasticsearch-ruby >= 8.0 returns
|
26
|
+
# the response wrapped in a Elasticsearch::API::Response::Response object. We are unwrapping it
|
27
|
+
# to keep the same interface. But we may want to coerce it to some internal object in the future.
|
28
|
+
def coerce_exception
|
29
|
+
resp = yield
|
30
|
+
if resp.class.name.start_with?('Elasticsearch::API::Response')
|
31
|
+
resp = resp.body
|
32
|
+
end
|
33
|
+
resp
|
34
|
+
rescue => exception
|
35
|
+
name = Hstring.new(exception.class.name)
|
36
|
+
if /^(Elasticsearch|Elastic|OpenSearch)?::Transport::Transport::Errors/.match?(name.value) && \
|
37
|
+
(exception_class = Esse::Transport::ERRORS[name.demodulize.value])
|
38
|
+
raise exception_class.new(exception.message)
|
39
|
+
else
|
40
|
+
raise exception
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/esse/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos G. Zimmermann
|
8
8
|
autorequire:
|
9
9
|
bindir: exec
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3.
|
103
|
+
version: '3.12'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '3.
|
110
|
+
version: '3.12'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: webmock
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,9 +198,11 @@ dependencies:
|
|
198
198
|
- - "~>"
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '2.4'
|
201
|
-
description:
|
202
|
-
|
203
|
-
and
|
201
|
+
description: With all elegance of Ruby and ElasticSearch flexibility this gem brings
|
202
|
+
to you the best of both worlds. Provides a solid architecture allowing to easily
|
203
|
+
Extract, Transform, Enrich and Load data from any data source into ElasticSearch/OpenSearch
|
204
|
+
and also to search it. It is framework-agnostic, which means you can use it with
|
205
|
+
any Ruby framework or even without any framework at all.
|
204
206
|
email:
|
205
207
|
- mgzmaster@gmail.com
|
206
208
|
executables:
|
@@ -210,18 +212,6 @@ extra_rdoc_files: []
|
|
210
212
|
files:
|
211
213
|
- exec/esse
|
212
214
|
- lib/esse.rb
|
213
|
-
- lib/esse/backend/index.rb
|
214
|
-
- lib/esse/backend/index/aliases.rb
|
215
|
-
- lib/esse/backend/index/close.rb
|
216
|
-
- lib/esse/backend/index/create.rb
|
217
|
-
- lib/esse/backend/index/delete.rb
|
218
|
-
- lib/esse/backend/index/documents.rb
|
219
|
-
- lib/esse/backend/index/existance.rb
|
220
|
-
- lib/esse/backend/index/open.rb
|
221
|
-
- lib/esse/backend/index/refresh.rb
|
222
|
-
- lib/esse/backend/index/reset.rb
|
223
|
-
- lib/esse/backend/index/update.rb
|
224
|
-
- lib/esse/backend/repository_backend.rb
|
225
215
|
- lib/esse/cli.rb
|
226
216
|
- lib/esse/cli/base.rb
|
227
217
|
- lib/esse/cli/event_listener.rb
|
@@ -239,12 +229,10 @@ files:
|
|
239
229
|
- lib/esse/cli/index/update_settings.rb
|
240
230
|
- lib/esse/cli/templates/collection.rb.erb
|
241
231
|
- lib/esse/cli/templates/config.rb.erb
|
232
|
+
- lib/esse/cli/templates/document.rb.erb
|
242
233
|
- lib/esse/cli/templates/index.rb.erb
|
243
234
|
- lib/esse/cli/templates/mappings.json
|
244
|
-
- lib/esse/cli/templates/serializer.rb.erb
|
245
235
|
- lib/esse/cli/templates/settings.json
|
246
|
-
- lib/esse/client_proxy.rb
|
247
|
-
- lib/esse/client_proxy/search.rb
|
248
236
|
- lib/esse/cluster.rb
|
249
237
|
- lib/esse/cluster_engine.rb
|
250
238
|
- lib/esse/collection.rb
|
@@ -252,8 +240,13 @@ files:
|
|
252
240
|
- lib/esse/core.rb
|
253
241
|
- lib/esse/deprecations.rb
|
254
242
|
- lib/esse/deprecations/cluster.rb
|
243
|
+
- lib/esse/deprecations/deprecate.rb
|
255
244
|
- lib/esse/deprecations/index.rb
|
245
|
+
- lib/esse/deprecations/index_backend_delegator.rb
|
256
246
|
- lib/esse/deprecations/repository.rb
|
247
|
+
- lib/esse/deprecations/repository_backend_delegator.rb
|
248
|
+
- lib/esse/deprecations/serializer.rb
|
249
|
+
- lib/esse/document.rb
|
257
250
|
- lib/esse/dynamic_template.rb
|
258
251
|
- lib/esse/errors.rb
|
259
252
|
- lib/esse/events.rb
|
@@ -265,10 +258,12 @@ files:
|
|
265
258
|
- lib/esse/import/request_body.rb
|
266
259
|
- lib/esse/index.rb
|
267
260
|
- lib/esse/index/actions.rb
|
261
|
+
- lib/esse/index/aliases.rb
|
268
262
|
- lib/esse/index/attributes.rb
|
269
|
-
- lib/esse/index/backend.rb
|
270
263
|
- lib/esse/index/base.rb
|
271
264
|
- lib/esse/index/descendants.rb
|
265
|
+
- lib/esse/index/documents.rb
|
266
|
+
- lib/esse/index/indices.rb
|
272
267
|
- lib/esse/index/inheritance.rb
|
273
268
|
- lib/esse/index/mappings.rb
|
274
269
|
- lib/esse/index/object_document_mapper.rb
|
@@ -287,12 +282,17 @@ files:
|
|
287
282
|
- lib/esse/primitives/output.rb
|
288
283
|
- lib/esse/repository.rb
|
289
284
|
- lib/esse/repository/actions.rb
|
290
|
-
- lib/esse/repository/
|
285
|
+
- lib/esse/repository/documents.rb
|
291
286
|
- lib/esse/repository/object_document_mapper.rb
|
292
287
|
- lib/esse/search/query.rb
|
293
288
|
- lib/esse/search/response.rb
|
294
|
-
- lib/esse/serializer.rb
|
295
289
|
- lib/esse/template_loader.rb
|
290
|
+
- lib/esse/transport.rb
|
291
|
+
- lib/esse/transport/aliases.rb
|
292
|
+
- lib/esse/transport/documents.rb
|
293
|
+
- lib/esse/transport/health.rb
|
294
|
+
- lib/esse/transport/indices.rb
|
295
|
+
- lib/esse/transport/search.rb
|
296
296
|
- lib/esse/version.rb
|
297
297
|
homepage: https://github.com/marcosgz/esse
|
298
298
|
licenses:
|
@@ -316,9 +316,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
316
316
|
- !ruby/object:Gem::Version
|
317
317
|
version: '0'
|
318
318
|
requirements: []
|
319
|
-
rubygems_version: 3.
|
319
|
+
rubygems_version: 3.2.32
|
320
320
|
signing_key:
|
321
321
|
specification_version: 4
|
322
|
-
summary: Pure Ruby
|
323
|
-
|
322
|
+
summary: Pure Ruby and framework-agnostic ElasticSearch/OpenSearch toolkit for building
|
323
|
+
indexers and searchers
|
324
324
|
test_files: []
|
@@ -1,73 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
# Return a list of index aliases.
|
8
|
-
#
|
9
|
-
# @param options [Hash] Hash of paramenters that will be passed along to elasticsearch request
|
10
|
-
# @param options [Array] :index list of serialized documents to be indexed(Optional)
|
11
|
-
#
|
12
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.5/indices-aliases.html
|
13
|
-
def aliases(**options)
|
14
|
-
response = coerce_exception { client.indices.get_alias({ index: index_name, name: '*' }.merge(options)) }
|
15
|
-
idx_name = response.keys.find { |idx| idx.start_with?(index_name) }
|
16
|
-
return [] unless idx_name
|
17
|
-
|
18
|
-
response.dig(idx_name, 'aliases')&.keys || []
|
19
|
-
rescue NotFoundError
|
20
|
-
[]
|
21
|
-
end
|
22
|
-
|
23
|
-
# Returns a list of indices.
|
24
|
-
#
|
25
|
-
# @param options [Hash] Hash of paramenters that will be passed along to elasticsearch request
|
26
|
-
# @return [Array] list of indices that match with `index_name`.
|
27
|
-
def indices(**options)
|
28
|
-
coerce_exception { client.indices.get_alias({ name: index_name }.merge(options)).keys }
|
29
|
-
rescue NotFoundError
|
30
|
-
[]
|
31
|
-
end
|
32
|
-
|
33
|
-
# Replaces all existing aliases by the respective suffixed index from argument.
|
34
|
-
#
|
35
|
-
# @param options [Hash] Hash of paramenters that will be passed along to elasticsearch request
|
36
|
-
# @option [String] :suffix The suffix of the index used for versioning.
|
37
|
-
# @raise [Esse::Backend::NotFoundError] in case of failure
|
38
|
-
# @return [Hash] the elasticsearch response
|
39
|
-
def update_aliases!(suffix:, **options)
|
40
|
-
raise(ArgumentError, 'index suffix cannot be nil') if suffix.nil?
|
41
|
-
|
42
|
-
options[:body] = {
|
43
|
-
actions: [
|
44
|
-
*indices.map do |index|
|
45
|
-
{ remove: { index: index, alias: index_name } }
|
46
|
-
end,
|
47
|
-
{ add: {index: build_real_index_name(suffix), alias: index_name } }
|
48
|
-
],
|
49
|
-
}
|
50
|
-
|
51
|
-
Esse::Events.instrument('elasticsearch.update_aliases') do |payload|
|
52
|
-
payload[:request] = options
|
53
|
-
payload[:response] = coerce_exception { client.indices.update_aliases(options)}
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Replaces all existing aliases by the respective suffixed index from argument.
|
58
|
-
#
|
59
|
-
# @param options [Hash] Hash of paramenters that will be passed along to elasticsearch request
|
60
|
-
# @option [String] :suffix The suffix of the index used for versioning.
|
61
|
-
# @raise [Esse::Backend::NotFoundError] in case of failure
|
62
|
-
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
63
|
-
def update_aliases(suffix:, **options)
|
64
|
-
update_aliases!(suffix: suffix, **options)
|
65
|
-
rescue NotFoundError
|
66
|
-
{ 'errors' => true }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
include InstanceMethods
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
# Close an index (keep the data on disk, but deny operations with the index).
|
8
|
-
#
|
9
|
-
# @option options [String, nil] :suffix The index suffix. Defaults to the index_version.
|
10
|
-
# Use nil if you want to check existence of the `index_name` index or alias.
|
11
|
-
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
12
|
-
# are open, closed or both. (options: open, closed)
|
13
|
-
# @option options [String] :ignore_indices When performed on multiple indices, allows to ignore
|
14
|
-
# `missing` ones (options: none, missing) @until 1.0
|
15
|
-
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
16
|
-
# unavailable (missing, closed, etc)
|
17
|
-
# @option options [Time] :timeout Explicit operation timeout
|
18
|
-
# @raise [Esse::Backend::ServerError]
|
19
|
-
# in case of failure
|
20
|
-
# @return [Hash] the elasticsearch response
|
21
|
-
#
|
22
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html
|
23
|
-
def close!(suffix: index_version, **options)
|
24
|
-
Esse::Events.instrument('elasticsearch.close') do |payload|
|
25
|
-
payload[:request] = attributes = options.merge(index: index_name(suffix: suffix))
|
26
|
-
payload[:response] = coerce_exception { client.indices.close(**attributes) }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Close an index (keep the data on disk, but deny operations with the index).
|
31
|
-
#
|
32
|
-
# @option options [String, nil] :suffix The index suffix. Defaults to the index_version.
|
33
|
-
# Use nil if you want to check existence of the `index_name` index or alias.
|
34
|
-
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
35
|
-
# are open, closed or both. (options: open, closed)
|
36
|
-
# @option options [String] :ignore_indices When performed on multiple indices, allows to ignore
|
37
|
-
# `missing` ones (options: none, missing) @until 1.0
|
38
|
-
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
39
|
-
# unavailable (missing, closed, etc)
|
40
|
-
# @option options [Time] :timeout Explicit operation timeout
|
41
|
-
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
42
|
-
#
|
43
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html
|
44
|
-
def close(suffix: index_version, **options)
|
45
|
-
close!(suffix: suffix, **options)
|
46
|
-
rescue ServerError
|
47
|
-
{ 'errors' => true }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
include InstanceMethods
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
DEFAULT_OPTIONS = {
|
8
|
-
alias: true,
|
9
|
-
}.freeze
|
10
|
-
|
11
|
-
# Creates index and applies mappings and settings.
|
12
|
-
#
|
13
|
-
# UsersIndex.elasticsearch.create_index # creates index named `<prefix_>users_<suffix|index_version|timestamp>`
|
14
|
-
#
|
15
|
-
# @param options [Hash] Options hash
|
16
|
-
# @option options [Boolean] :alias Update `index_name` alias along with the new index
|
17
|
-
# @option options [String] :suffix The index suffix. Defaults to the `IndexClass#index_version` or
|
18
|
-
# `Esse.timestamp`. Suffixed index names might be used for zero-downtime mapping change.
|
19
|
-
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
20
|
-
#
|
21
|
-
# @see http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/
|
22
|
-
def create_index(suffix: index_version, **options)
|
23
|
-
create_index!(suffix: suffix, **options)
|
24
|
-
rescue ServerError
|
25
|
-
{ 'errors' => true }
|
26
|
-
end
|
27
|
-
|
28
|
-
# Creates index and applies mappings and settings.
|
29
|
-
#
|
30
|
-
# UsersIndex.elasticsearch.create_index! # creates index named `<prefix_>users_<suffix|index_version|timestamp>`
|
31
|
-
#
|
32
|
-
# @param options [Hash] Options hash
|
33
|
-
# @option options [Boolean] :alias Update `index_name` alias along with the new index
|
34
|
-
# @option options [String] :suffix The index suffix. Defaults to the `IndexClass#index_version` or
|
35
|
-
# `Esse.timestamp`. Suffixed index names might be used for zero-downtime mapping change.
|
36
|
-
# @option arguments [String] :wait_for_active_shards Set the number of active shards
|
37
|
-
# to wait for before the operation returns.
|
38
|
-
# @option arguments [Time] :timeout Explicit operation timeout
|
39
|
-
# @option arguments [Time] :master_timeout Specify timeout for connection to master
|
40
|
-
# @option arguments [Hash] :headers Custom HTTP headers
|
41
|
-
# @option arguments [Hash] :body The configuration for the index (`settings` and `mappings`)
|
42
|
-
# @raise [Esse::Backend::NotFoundError] when index already exists
|
43
|
-
# @return [Hash] the elasticsearch response
|
44
|
-
#
|
45
|
-
# @see http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/
|
46
|
-
def create_index!(suffix: index_version, **options)
|
47
|
-
options = DEFAULT_OPTIONS.merge(options)
|
48
|
-
name = build_real_index_name(suffix)
|
49
|
-
definition = [settings_hash, mappings_hash].reduce(&:merge)
|
50
|
-
|
51
|
-
if options.delete(:alias) && name != index_name
|
52
|
-
definition[:aliases] = { index_name => {} }
|
53
|
-
end
|
54
|
-
|
55
|
-
Esse::Events.instrument('elasticsearch.create_index') do |payload|
|
56
|
-
payload[:request] = opts = options.merge(index: name, body: definition)
|
57
|
-
payload[:response] = response = coerce_exception { client.indices.create(**opts) }
|
58
|
-
coerce_exception { cluster.wait_for_status! } if response
|
59
|
-
response
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
include InstanceMethods
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
# Deletes ES index
|
8
|
-
#
|
9
|
-
# UsersIndex.elasticsearch.delete_index! # deletes `<prefix_>users<_suffix|_index_version|_timestamp>` index
|
10
|
-
#
|
11
|
-
# @param suffix [String, nil] The index suffix Use nil if you want to delete the current index.
|
12
|
-
# @raise [Esse::Backend::NotFoundError] when index does not exists
|
13
|
-
# @return [Hash] elasticsearch response
|
14
|
-
def delete_index!(suffix: index_version, **options)
|
15
|
-
Esse::Events.instrument('elasticsearch.delete_index') do |payload|
|
16
|
-
payload[:request] = opts = options.merge(index: index_name(suffix: suffix))
|
17
|
-
payload[:response] = response = coerce_exception { client.indices.delete(**opts) }
|
18
|
-
coerce_exception { cluster.wait_for_status! } if response
|
19
|
-
response
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Deletes ES index
|
24
|
-
#
|
25
|
-
# UsersIndex.elasticsearch.delete_index # deletes `<prefix_>users<_suffix|_index_version|_timestamp>` index
|
26
|
-
#
|
27
|
-
# @param suffix [String, nil] The index suffix Use nil if you want to delete the current index.
|
28
|
-
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
29
|
-
def delete_index(suffix: index_version, **options)
|
30
|
-
delete_index!(suffix: suffix, **options)
|
31
|
-
rescue ServerError
|
32
|
-
{ 'errors' => true }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
include InstanceMethods
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|