esse 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exec/esse +2 -0
- data/lib/esse/cli/event_listener.rb +4 -5
- data/lib/esse/cli/extensions_loader.rb +22 -0
- 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 +6 -0
- data/lib/esse/cluster.rb +44 -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/search.rb +8 -1
- 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/primitives/hash_utils.rb +11 -0
- 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/dsl.rb +61 -0
- data/lib/esse/search/query.rb +15 -17
- 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 +30 -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
@@ -0,0 +1,192 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
class Transport
|
5
|
+
module InstanceMethods
|
6
|
+
# Creates an index with optional settings and mappings.
|
7
|
+
#
|
8
|
+
# @param options [Hash] Options hash
|
9
|
+
# @option [String] :index The name of the index
|
10
|
+
# @option [String] :wait_for_active_shards Set the number of active shards to wait for before the operation returns.
|
11
|
+
# @option [Time] :timeout Explicit operation timeout
|
12
|
+
# @option [Time] :master_timeout Specify timeout for connection to master
|
13
|
+
# @option [Hash] :headers Custom HTTP headers
|
14
|
+
# @option [Hash] :body The configuration for the index (`settings` and `mappings`)
|
15
|
+
# @option [String] :wait_for_status Wait until cluster is in a specific state (options: green, yellow, red)
|
16
|
+
#
|
17
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
|
18
|
+
def create_index(index:, wait_for_status: nil, **options)
|
19
|
+
throw_error_when_readonly!
|
20
|
+
|
21
|
+
Esse::Events.instrument('elasticsearch.create_index') do |payload|
|
22
|
+
payload[:request] = opts = options.merge(index: index)
|
23
|
+
payload[:response] = response = coerce_exception { client.indices.create(**opts) }
|
24
|
+
if response && response['acknowledged']
|
25
|
+
coerce_exception do
|
26
|
+
cluster.wait_for_status!(status: (wait_for_status || cluster.wait_for_status), index: index)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns information about whether a particular index exists.
|
34
|
+
#
|
35
|
+
# @option [List] :index A comma-separated list of index names
|
36
|
+
# @option [Boolean] :local Return local information, do not retrieve the state from master node (default: false)
|
37
|
+
# @option [Boolean] :ignore_unavailable Ignore unavailable indexes (default: false)
|
38
|
+
# @option [Boolean] :allow_no_indices Ignore if a wildcard expression resolves to no concrete indices (default: false)
|
39
|
+
# @option [String] :expand_wildcards Whether wildcard expressions should get expanded to open or closed indices (default: open) (options: open, closed, hidden, none, all)
|
40
|
+
# @option [Boolean] :flat_settings Return settings in flat format (default: false)
|
41
|
+
# @option [Boolean] :include_defaults Whether to return all default setting for each of the indices.
|
42
|
+
# @option [Hash] :headers Custom HTTP headers
|
43
|
+
#
|
44
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html
|
45
|
+
def index_exist?(index:, **options)
|
46
|
+
Esse::Events.instrument('elasticsearch.index_exist') do |payload|
|
47
|
+
payload[:request] = opts = options.merge(index: index)
|
48
|
+
payload[:response] = coerce_exception { client.indices.exists(**opts) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Deletes an index.
|
53
|
+
#
|
54
|
+
# @option [List] :index A comma-separated list of indices to delete; use `_all` or `*` string to delete all indices
|
55
|
+
# @option [Time] :timeout Explicit operation timeout
|
56
|
+
# @option [Time] :master_timeout Specify timeout for connection to master
|
57
|
+
# @option [Boolean] :ignore_unavailable Ignore unavailable indexes (default: false)
|
58
|
+
# @option [Boolean] :allow_no_indices Ignore if a wildcard expression resolves to no concrete indices (default: false)
|
59
|
+
# @option [String] :expand_wildcards Whether wildcard expressions should get expanded to open, closed, or hidden indices (options: open, closed, hidden, none, all)
|
60
|
+
# @option [Hash] :headers Custom HTTP headers
|
61
|
+
# @option [String] :wait_for_status Wait until cluster is in a specific state (options: green, yellow, red)
|
62
|
+
#
|
63
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html
|
64
|
+
def delete_index(index:, wait_for_status: nil, **options)
|
65
|
+
throw_error_when_readonly!
|
66
|
+
|
67
|
+
Esse::Events.instrument('elasticsearch.delete_index') do |payload|
|
68
|
+
payload[:request] = opts = options.merge(index: index)
|
69
|
+
payload[:response] = response = coerce_exception { client.indices.delete(**opts) }
|
70
|
+
if response && response['acknowledged']
|
71
|
+
coerce_exception do
|
72
|
+
cluster.wait_for_status!(status: (wait_for_status || cluster.wait_for_status), index: index)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
response
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Open a previously closed index
|
80
|
+
#
|
81
|
+
# @option options [List] :index A comma separated list of indices to open
|
82
|
+
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
83
|
+
# are open, closed or both. (options: open, closed)
|
84
|
+
# @option options [String] :ignore_indices When performed on multiple indices, allows to ignore
|
85
|
+
# `missing` ones (options: none, missing) @until 1.0
|
86
|
+
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
87
|
+
# unavailable (missing, closed, etc)
|
88
|
+
# @option options [Time] :timeout Explicit operation timeout
|
89
|
+
# @raise [Esse::Transport::ServerError]
|
90
|
+
# in case of failure
|
91
|
+
# @return [Hash] the elasticsearch response
|
92
|
+
#
|
93
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-open.html
|
94
|
+
def open(index:, **options)
|
95
|
+
throw_error_when_readonly!
|
96
|
+
|
97
|
+
Esse::Events.instrument('elasticsearch.open') do |payload|
|
98
|
+
payload[:request] = attributes = options.merge(index: index)
|
99
|
+
payload[:response] = coerce_exception { client.indices.open(**attributes) }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Close an index (keep the data on disk, but deny operations with the index).
|
104
|
+
#
|
105
|
+
# @option options [List] :index A comma separated list of indices to open
|
106
|
+
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
107
|
+
# are open, closed or both. (options: open, closed)
|
108
|
+
# @option options [String] :ignore_indices When performed on multiple indices, allows to ignore
|
109
|
+
# `missing` ones (options: none, missing) @until 1.0
|
110
|
+
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
111
|
+
# unavailable (missing, closed, etc)
|
112
|
+
# @option options [Time] :timeout Explicit operation timeout
|
113
|
+
# @raise [Esse::Transport::ServerError] in case of failure
|
114
|
+
# @return [Hash] the elasticsearch response
|
115
|
+
#
|
116
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html
|
117
|
+
def close(index:, **options)
|
118
|
+
throw_error_when_readonly!
|
119
|
+
|
120
|
+
Esse::Events.instrument('elasticsearch.close') do |payload|
|
121
|
+
payload[:request] = attributes = options.merge(index: index)
|
122
|
+
payload[:response] = coerce_exception { client.indices.close(**attributes) }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Performs the refresh operation in one or more indices.
|
127
|
+
#
|
128
|
+
# @option options [List] :index A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
|
129
|
+
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
|
130
|
+
# @option options [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
|
131
|
+
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, hidden, none, all)
|
132
|
+
# @option options [Hash] :headers Custom HTTP headers
|
133
|
+
#
|
134
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html
|
135
|
+
def refresh(index:, **options)
|
136
|
+
throw_error_when_readonly!
|
137
|
+
|
138
|
+
Esse::Events.instrument('elasticsearch.refresh') do |payload|
|
139
|
+
payload[:request] = attributes = options.merge(index: index)
|
140
|
+
payload[:response] = coerce_exception { client.indices.refresh(**attributes) }
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# Updates the index mappings.
|
145
|
+
#
|
146
|
+
# @option options [List] :index A comma-separated list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices.
|
147
|
+
# @option options [Time] :timeout Explicit operation timeout
|
148
|
+
# @option options [Time] :master_timeout Specify timeout for connection to master
|
149
|
+
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
|
150
|
+
# @option options [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
|
151
|
+
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, hidden, none, all)
|
152
|
+
# @option options [Boolean] :write_index_only When true, applies mappings only to the write index of an alias or data stream
|
153
|
+
# @option options [Hash] :headers Custom HTTP headers
|
154
|
+
# @option options [Hash] :body The mapping definition (*Required*)
|
155
|
+
#
|
156
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
|
157
|
+
def update_mapping(index:, body:, **options)
|
158
|
+
throw_error_when_readonly!
|
159
|
+
|
160
|
+
Esse::Events.instrument('elasticsearch.update_mapping') do |payload|
|
161
|
+
payload[:request] = opts = options.merge(index: index, body: body)
|
162
|
+
payload[:response] = coerce_exception { client.indices.put_mapping(**opts) }
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Updates the index settings.
|
167
|
+
#
|
168
|
+
# @option options [List] :index A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
|
169
|
+
# @option options [Time] :master_timeout Specify timeout for connection to master
|
170
|
+
# @option options [Time] :timeout Explicit operation timeout
|
171
|
+
# @option options [Boolean] :preserve_existing Whether to update existing settings. If set to `true` existing settings on an index remain unchanged, the default is `false`
|
172
|
+
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
|
173
|
+
# @option options [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
|
174
|
+
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, hidden, none, all)
|
175
|
+
# @option options [Boolean] :flat_settings Return settings in flat format (default: false)
|
176
|
+
# @option options [Hash] :headers Custom HTTP headers
|
177
|
+
# @option options [Hash] :body The index settings to be updated (*Required*)
|
178
|
+
#
|
179
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html
|
180
|
+
def update_settings(index:, body:, **options)
|
181
|
+
throw_error_when_readonly!
|
182
|
+
|
183
|
+
Esse::Events.instrument('elasticsearch.update_settings') do |payload|
|
184
|
+
payload[:request] = opts = options.merge(index: index, body: body)
|
185
|
+
payload[:response] = coerce_exception { client.indices.put_settings(**opts) }
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
include InstanceMethods
|
191
|
+
end
|
192
|
+
end
|
@@ -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.4
|
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-15 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,21 +212,10 @@ 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
|
218
|
+
- lib/esse/cli/extensions_loader.rb
|
228
219
|
- lib/esse/cli/generate.rb
|
229
220
|
- lib/esse/cli/index.rb
|
230
221
|
- lib/esse/cli/index/base_operation.rb
|
@@ -239,12 +230,10 @@ files:
|
|
239
230
|
- lib/esse/cli/index/update_settings.rb
|
240
231
|
- lib/esse/cli/templates/collection.rb.erb
|
241
232
|
- lib/esse/cli/templates/config.rb.erb
|
233
|
+
- lib/esse/cli/templates/document.rb.erb
|
242
234
|
- lib/esse/cli/templates/index.rb.erb
|
243
235
|
- lib/esse/cli/templates/mappings.json
|
244
|
-
- lib/esse/cli/templates/serializer.rb.erb
|
245
236
|
- lib/esse/cli/templates/settings.json
|
246
|
-
- lib/esse/client_proxy.rb
|
247
|
-
- lib/esse/client_proxy/search.rb
|
248
237
|
- lib/esse/cluster.rb
|
249
238
|
- lib/esse/cluster_engine.rb
|
250
239
|
- lib/esse/collection.rb
|
@@ -252,8 +241,13 @@ files:
|
|
252
241
|
- lib/esse/core.rb
|
253
242
|
- lib/esse/deprecations.rb
|
254
243
|
- lib/esse/deprecations/cluster.rb
|
244
|
+
- lib/esse/deprecations/deprecate.rb
|
255
245
|
- lib/esse/deprecations/index.rb
|
246
|
+
- lib/esse/deprecations/index_backend_delegator.rb
|
256
247
|
- lib/esse/deprecations/repository.rb
|
248
|
+
- lib/esse/deprecations/repository_backend_delegator.rb
|
249
|
+
- lib/esse/deprecations/serializer.rb
|
250
|
+
- lib/esse/document.rb
|
257
251
|
- lib/esse/dynamic_template.rb
|
258
252
|
- lib/esse/errors.rb
|
259
253
|
- lib/esse/events.rb
|
@@ -265,10 +259,12 @@ files:
|
|
265
259
|
- lib/esse/import/request_body.rb
|
266
260
|
- lib/esse/index.rb
|
267
261
|
- lib/esse/index/actions.rb
|
262
|
+
- lib/esse/index/aliases.rb
|
268
263
|
- lib/esse/index/attributes.rb
|
269
|
-
- lib/esse/index/backend.rb
|
270
264
|
- lib/esse/index/base.rb
|
271
265
|
- lib/esse/index/descendants.rb
|
266
|
+
- lib/esse/index/documents.rb
|
267
|
+
- lib/esse/index/indices.rb
|
272
268
|
- lib/esse/index/inheritance.rb
|
273
269
|
- lib/esse/index/mappings.rb
|
274
270
|
- lib/esse/index/object_document_mapper.rb
|
@@ -287,12 +283,18 @@ files:
|
|
287
283
|
- lib/esse/primitives/output.rb
|
288
284
|
- lib/esse/repository.rb
|
289
285
|
- lib/esse/repository/actions.rb
|
290
|
-
- lib/esse/repository/
|
286
|
+
- lib/esse/repository/documents.rb
|
291
287
|
- lib/esse/repository/object_document_mapper.rb
|
292
288
|
- lib/esse/search/query.rb
|
289
|
+
- lib/esse/search/query/dsl.rb
|
293
290
|
- lib/esse/search/response.rb
|
294
|
-
- lib/esse/serializer.rb
|
295
291
|
- lib/esse/template_loader.rb
|
292
|
+
- lib/esse/transport.rb
|
293
|
+
- lib/esse/transport/aliases.rb
|
294
|
+
- lib/esse/transport/documents.rb
|
295
|
+
- lib/esse/transport/health.rb
|
296
|
+
- lib/esse/transport/indices.rb
|
297
|
+
- lib/esse/transport/search.rb
|
296
298
|
- lib/esse/version.rb
|
297
299
|
homepage: https://github.com/marcosgz/esse
|
298
300
|
licenses:
|
@@ -316,9 +318,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
316
318
|
- !ruby/object:Gem::Version
|
317
319
|
version: '0'
|
318
320
|
requirements: []
|
319
|
-
rubygems_version: 3.
|
321
|
+
rubygems_version: 3.2.32
|
320
322
|
signing_key:
|
321
323
|
specification_version: 4
|
322
|
-
summary: Pure Ruby
|
323
|
-
|
324
|
+
summary: Pure Ruby and framework-agnostic ElasticSearch/OpenSearch toolkit for building
|
325
|
+
indexers and searchers
|
324
326
|
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
|