esse 0.0.3 → 0.1.2
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/exec/esse +3 -1
- data/lib/esse/backend/index/aliases.rb +8 -4
- data/lib/esse/backend/index/close.rb +6 -5
- data/lib/esse/backend/index/create.rb +20 -9
- data/lib/esse/backend/index/delete.rb +15 -14
- data/lib/esse/backend/index/documents.rb +2 -2
- data/lib/esse/backend/index/existance.rb +2 -3
- data/lib/esse/backend/index/open.rb +6 -5
- data/lib/esse/backend/index/refresh.rb +43 -0
- data/lib/esse/backend/index/reset.rb +33 -0
- data/lib/esse/backend/index/update.rb +37 -15
- data/lib/esse/backend/index.rb +18 -4
- data/lib/esse/backend/index_type/documents.rb +53 -42
- data/lib/esse/backend/index_type.rb +7 -2
- data/lib/esse/cli/event_listener.rb +87 -0
- data/lib/esse/cli/generate.rb +9 -4
- data/lib/esse/cli/index/base_operation.rb +76 -0
- data/lib/esse/cli/index/close.rb +26 -0
- data/lib/esse/cli/index/create.rb +26 -0
- data/lib/esse/cli/index/delete.rb +26 -0
- data/lib/esse/cli/index/import.rb +26 -0
- data/lib/esse/cli/index/open.rb +26 -0
- data/lib/esse/cli/index/reset.rb +26 -0
- data/lib/esse/cli/index/update_aliases.rb +32 -0
- data/lib/esse/cli/index/update_mapping.rb +33 -0
- data/lib/esse/cli/index/update_settings.rb +26 -0
- data/lib/esse/cli/index.rb +78 -2
- data/lib/esse/cli/templates/config.rb.erb +20 -0
- data/lib/esse/cli/templates/index.rb.erb +76 -11
- data/lib/esse/cli/templates/type_collection.rb.erb +41 -0
- data/lib/esse/cli/templates/{mappings.json → type_mappings.json} +0 -0
- data/lib/esse/cli/templates/type_serializer.rb.erb +23 -0
- data/lib/esse/cli.rb +75 -3
- data/lib/esse/cluster.rb +22 -6
- data/lib/esse/config.rb +39 -5
- data/lib/esse/core.rb +18 -36
- data/lib/esse/errors.rb +47 -0
- data/lib/esse/events/bus.rb +103 -0
- data/lib/esse/events/event.rb +64 -0
- data/lib/esse/events/publisher.rb +119 -0
- data/lib/esse/events.rb +49 -0
- data/lib/esse/index/backend.rb +2 -1
- data/lib/esse/index/base.rb +4 -6
- data/lib/esse/index/mappings.rb +2 -3
- data/lib/esse/index/settings.rb +7 -8
- data/lib/esse/index.rb +2 -1
- data/lib/esse/index_mapping.rb +2 -2
- data/lib/esse/index_setting.rb +8 -4
- data/lib/esse/index_type/actions.rb +2 -1
- data/lib/esse/index_type/backend.rb +2 -1
- data/lib/esse/index_type/mappings.rb +2 -2
- data/lib/esse/index_type.rb +6 -1
- data/lib/esse/logging.rb +19 -0
- data/lib/esse/object_document_mapper.rb +96 -0
- data/lib/esse/primitives/hash_utils.rb +40 -0
- data/lib/esse/primitives/hstring.rb +4 -3
- data/lib/esse/primitives/output.rb +64 -0
- data/lib/esse/primitives.rb +1 -0
- data/lib/esse/template_loader.rb +1 -1
- data/lib/esse/version.rb +1 -1
- data/lib/esse.rb +12 -3
- metadata +124 -21
- data/.gitignore +0 -12
- data/.rubocop.yml +0 -128
- data/CHANGELOG.md +0 -0
- data/Gemfile +0 -7
- data/Gemfile.lock +0 -60
- data/LICENSE.txt +0 -21
- data/README.md +0 -52
- data/Rakefile +0 -4
- data/bin/console +0 -22
- data/bin/setup +0 -8
- data/esse.gemspec +0 -39
- data/lib/esse/cli/templates/serializer.rb.erb +0 -14
- data/lib/esse/index_type/serializer.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dff3560f305debeee691263267e43df0e70a17591f6ecfc897025a5c07ada8a
|
4
|
+
data.tar.gz: a8ba452b0bfc81210f104293f852ecacaef585ea23b2e8f24177197fa2555e69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73bfc1a130c18df947cd02120087eed2b571fa174b84009b687dc0e343697aec1a1a20ae00eb0fc8465a9ad603d95318c02d324b98fe811baddc0b08d3533e28
|
7
|
+
data.tar.gz: 160aaf9fdef9da05108c1e966cfc03a45f9357aeb4682d551458546f66dc067d0585e52f0836aa0b4ee8fb5d634d3b705bced6340e91a99013d571fcded5f574
|
data/exec/esse
CHANGED
@@ -44,10 +44,14 @@ module Esse
|
|
44
44
|
*indices.map do |index|
|
45
45
|
{ remove: { index: index, alias: index_name } }
|
46
46
|
end,
|
47
|
-
{ add: {index:
|
47
|
+
{ add: {index: build_real_index_name(suffix), alias: index_name } }
|
48
48
|
],
|
49
49
|
}
|
50
|
-
|
50
|
+
|
51
|
+
Esse::Events.instrument('elasticsearch.update_aliases') do |payload|
|
52
|
+
payload[:request] = options
|
53
|
+
payload[:response] = client.indices.update_aliases(options)
|
54
|
+
end
|
51
55
|
end
|
52
56
|
|
53
57
|
# Replaces all existing aliases by the respective suffixed index from argument.
|
@@ -55,11 +59,11 @@ module Esse
|
|
55
59
|
# @param options [Hash] Hash of paramenters that will be passed along to elasticsearch request
|
56
60
|
# @option [String] :suffix The suffix of the index used for versioning.
|
57
61
|
# @raise [Elasticsearch::Transport::Transport::Errors::NotFound] in case of failure
|
58
|
-
# @return [Hash
|
62
|
+
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
59
63
|
def update_aliases(suffix:, **options)
|
60
64
|
update_aliases!(suffix: suffix, **options)
|
61
65
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
62
|
-
|
66
|
+
{ 'errors' => true }
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
@@ -21,9 +21,10 @@ module Esse
|
|
21
21
|
#
|
22
22
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html
|
23
23
|
def close!(suffix: index_version, **options)
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
Esse::Events.instrument('elasticsearch.close') do |payload|
|
25
|
+
payload[:request] = attributes = options.merge(index: index_name(suffix: suffix))
|
26
|
+
payload[:response] = client.indices.close(**attributes)
|
27
|
+
end
|
27
28
|
end
|
28
29
|
|
29
30
|
# Close an index (keep the data on disk, but deny operations with the index).
|
@@ -37,13 +38,13 @@ module Esse
|
|
37
38
|
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
38
39
|
# unavailable (missing, closed, etc)
|
39
40
|
# @option options [Time] :timeout Explicit operation timeout
|
40
|
-
# @return [Hash
|
41
|
+
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
41
42
|
#
|
42
43
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html
|
43
44
|
def close(suffix: index_version, **options)
|
44
45
|
close!(suffix: suffix, **options)
|
45
46
|
rescue Elasticsearch::Transport::Transport::ServerError
|
46
|
-
|
47
|
+
{ 'errors' => true }
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
@@ -10,43 +10,54 @@ module Esse
|
|
10
10
|
|
11
11
|
# Creates index and applies mappings and settings.
|
12
12
|
#
|
13
|
-
# UsersIndex.
|
13
|
+
# UsersIndex.elasticsearch.create_index # creates index named `<prefix_>users_<suffix|index_version|timestamp>`
|
14
14
|
#
|
15
15
|
# @param options [Hash] Options hash
|
16
16
|
# @option options [Boolean] :alias Update `index_name` alias along with the new index
|
17
17
|
# @option options [String] :suffix The index suffix. Defaults to the `IndexClass#index_version` or
|
18
18
|
# `Esse.timestamp`. Suffixed index names might be used for zero-downtime mapping change.
|
19
|
-
# @return [Hash
|
19
|
+
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
20
20
|
#
|
21
21
|
# @see http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/
|
22
|
-
def create_index(suffix:
|
22
|
+
def create_index(suffix: index_version, **options)
|
23
23
|
create_index!(suffix: suffix, **options)
|
24
24
|
rescue Elasticsearch::Transport::Transport::Errors::BadRequest
|
25
|
-
|
25
|
+
{ 'errors' => true }
|
26
26
|
end
|
27
27
|
|
28
28
|
# Creates index and applies mappings and settings.
|
29
29
|
#
|
30
|
-
# UsersIndex.
|
30
|
+
# UsersIndex.elasticsearch.create_index! # creates index named `<prefix_>users_<suffix|index_version|timestamp>`
|
31
31
|
#
|
32
32
|
# @param options [Hash] Options hash
|
33
33
|
# @option options [Boolean] :alias Update `index_name` alias along with the new index
|
34
34
|
# @option options [String] :suffix The index suffix. Defaults to the `IndexClass#index_version` or
|
35
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`)
|
36
42
|
# @raise [Elasticsearch::Transport::Transport::Errors::NotFound] when index already exists
|
37
43
|
# @return [Hash] the elasticsearch response
|
38
44
|
#
|
39
45
|
# @see http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/
|
40
|
-
def create_index!(suffix:
|
46
|
+
def create_index!(suffix: index_version, **options)
|
41
47
|
options = DEFAULT_OPTIONS.merge(options)
|
42
|
-
name =
|
48
|
+
name = build_real_index_name(suffix)
|
43
49
|
definition = [settings_hash, mappings_hash].reduce(&:merge)
|
44
50
|
|
45
|
-
if options
|
51
|
+
if options.delete(:alias) && name != index_name
|
46
52
|
definition[:aliases] = { index_name => {} }
|
47
53
|
end
|
48
54
|
|
49
|
-
|
55
|
+
Esse::Events.instrument('elasticsearch.create_index') do |payload|
|
56
|
+
payload[:request] = opts = options.merge(index: name, body: definition)
|
57
|
+
payload[:response] = response = client.indices.create(**opts)
|
58
|
+
cluster.wait_for_status! if response
|
59
|
+
response
|
60
|
+
end
|
50
61
|
end
|
51
62
|
end
|
52
63
|
|
@@ -6,29 +6,30 @@ module Esse
|
|
6
6
|
module InstanceMethods
|
7
7
|
# Deletes ES index
|
8
8
|
#
|
9
|
-
# UsersIndex.
|
9
|
+
# UsersIndex.elasticsearch.delete_index! # deletes `<prefix_>users<_suffix|_index_version|_timestamp>` index
|
10
10
|
#
|
11
|
-
# @param
|
12
|
-
# @option [String, nil] :suffix The index suffix Use nil if you want to delete the current index.
|
11
|
+
# @param suffix [String, nil] The index suffix Use nil if you want to delete the current index.
|
13
12
|
# @raise [Elasticsearch::Transport::Transport::Errors::NotFound] when index does not exists
|
14
13
|
# @return [Hash] elasticsearch response
|
15
|
-
def delete_index!(suffix:)
|
16
|
-
|
17
|
-
|
18
|
-
|
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 = client.indices.delete(**opts)
|
18
|
+
cluster.wait_for_status! if response
|
19
|
+
response
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
# Deletes ES index
|
22
24
|
#
|
23
|
-
# UsersIndex.
|
25
|
+
# UsersIndex.elasticsearch.delete_index # deletes `<prefix_>users<_suffix|_index_version|_timestamp>` index
|
24
26
|
#
|
25
|
-
# @param
|
26
|
-
# @
|
27
|
-
|
28
|
-
|
29
|
-
delete_index!(suffix: suffix)
|
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)
|
30
31
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
31
|
-
|
32
|
+
{ 'errors' => true }
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
@@ -6,13 +6,13 @@ module Esse
|
|
6
6
|
module InstanceMethods
|
7
7
|
def import!(**options)
|
8
8
|
type_hash.each_value do |type|
|
9
|
-
type.
|
9
|
+
type.elasticsearch.import!(**options)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def import(**options)
|
14
14
|
type_hash.each_value do |type|
|
15
|
-
type.
|
15
|
+
type.elasticsearch.import(**options)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -6,14 +6,13 @@ module Esse
|
|
6
6
|
module InstanceMethods
|
7
7
|
# Checks the index existance. Returns true or false
|
8
8
|
#
|
9
|
-
# UsersIndex.
|
9
|
+
# UsersIndex.elasticsearch.exist? #=> true
|
10
10
|
#
|
11
11
|
# @param options [Hash] Options hash
|
12
12
|
# @option options [String, nil] :suffix The index suffix. Defaults to the index_version.
|
13
13
|
# Use nil if you want to check existence of the `index_name` index or alias.
|
14
14
|
def exist?(suffix: index_version)
|
15
|
-
|
16
|
-
client.indices.exists(index: name)
|
15
|
+
client.indices.exists(index: index_name(suffix: suffix))
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
@@ -21,9 +21,10 @@ module Esse
|
|
21
21
|
#
|
22
22
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-open.html
|
23
23
|
def open!(suffix: index_version, **options)
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
Esse::Events.instrument('elasticsearch.open') do |payload|
|
25
|
+
payload[:request] = attributes = options.merge(index: index_name(suffix: suffix))
|
26
|
+
payload[:response] = client.indices.open(**attributes)
|
27
|
+
end
|
27
28
|
end
|
28
29
|
|
29
30
|
# Open a previously closed index
|
@@ -37,13 +38,13 @@ module Esse
|
|
37
38
|
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
38
39
|
# unavailable (missing, closed, etc)
|
39
40
|
# @option options [Time] :timeout Explicit operation timeout
|
40
|
-
# @return [Hash
|
41
|
+
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
41
42
|
#
|
42
43
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-open.html
|
43
44
|
def open(suffix: index_version, **options)
|
44
45
|
open!(suffix: suffix, **options)
|
45
46
|
rescue Elasticsearch::Transport::Transport::ServerError
|
46
|
-
|
47
|
+
{ 'errors' => true }
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
module Backend
|
5
|
+
class Index
|
6
|
+
module InstanceMethods
|
7
|
+
# Performs the refresh operation in one or more indices.
|
8
|
+
#
|
9
|
+
# @note The refresh operation can adversely affect indexing throughput when used too frequently.
|
10
|
+
# @param :suffix [String, nil] :suffix The index suffix. Defaults to the index_version.
|
11
|
+
# A uniq index name will be generated if one index already exist with the given alias.
|
12
|
+
# @param options [Hash] Options hash
|
13
|
+
# @raise [Elasticsearch::Transport::Transport::Errors::BadRequest, Elasticsearch::Transport::Transport::Errors::NotFound]
|
14
|
+
# in case of failure
|
15
|
+
# @return [Hash] the elasticsearch response
|
16
|
+
#
|
17
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html
|
18
|
+
def refresh!(suffix: index_version, **options)
|
19
|
+
client.indices.refresh(
|
20
|
+
options.merge(index: index_name(suffix: suffix)),
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Performs the refresh operation in one or more indices.
|
25
|
+
#
|
26
|
+
# @note The refresh operation can adversely affect indexing throughput when used too frequently.
|
27
|
+
# @param :suffix [String, nil] :suffix The index suffix. Defaults to the index_version.
|
28
|
+
# A uniq index name will be generated if one index already exist with the given alias.
|
29
|
+
# @param options [Hash] Options hash
|
30
|
+
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
31
|
+
#
|
32
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html
|
33
|
+
def refresh(suffix: index_version, **options)
|
34
|
+
refresh!(suffix: suffix, **options)
|
35
|
+
rescue Elasticsearch::Transport::Transport::ServerError
|
36
|
+
{ 'errors' => true }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
include InstanceMethods
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
module Backend
|
5
|
+
class Index
|
6
|
+
module InstanceMethods
|
7
|
+
# Deletes, creates and imports data to the index. Performs zero-downtime index resetting.
|
8
|
+
#
|
9
|
+
# @option options [String, nil] :suffix The index suffix. Defaults to the index_version.
|
10
|
+
# A uniq index name will be generated if one index already exist with the given alias.
|
11
|
+
# @option options [Time] :timeout Explicit operation timeout
|
12
|
+
# @raise [Elasticsearch::Transport::Transport::Errors::BadRequest, Elasticsearch::Transport::Transport::Errors::NotFound]
|
13
|
+
# in case of failure
|
14
|
+
# @return [Hash] the elasticsearch response
|
15
|
+
#
|
16
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html
|
17
|
+
def reset_index!(suffix: index_version, **options)
|
18
|
+
existing = []
|
19
|
+
suffix ||= Esse.timestamp
|
20
|
+
suffix = Esse.timestamp while exist?(suffix: suffix).tap { |exist| existing << suffix if exist }
|
21
|
+
|
22
|
+
create_index!(suffix: suffix, **options)
|
23
|
+
import!(suffix: suffix, **options)
|
24
|
+
update_aliases!(suffix: suffix)
|
25
|
+
existing.each { |_s| delete_index!(suffix: suffix, **options) }
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
include InstanceMethods
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -27,9 +27,14 @@ module Esse
|
|
27
27
|
#
|
28
28
|
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/
|
29
29
|
def update_mapping!(suffix: index_version, **options)
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
Esse::Events.instrument('elasticsearch.update_mapping') do |payload|
|
31
|
+
body = mappings_hash.fetch(Esse::MAPPING_ROOT_KEY)
|
32
|
+
if (type = options[:type])
|
33
|
+
body = body[type.to_s] || body[type.to_sym]
|
34
|
+
end
|
35
|
+
payload[:request] = opts = options.merge(index: index_name(suffix: suffix), body: body)
|
36
|
+
payload[:response] = client.indices.put_mapping(**opts)
|
37
|
+
end
|
33
38
|
end
|
34
39
|
|
35
40
|
# Create or update a mapping
|
@@ -49,16 +54,15 @@ module Esse
|
|
49
54
|
# with the same name across all types
|
50
55
|
# @option options [Time] :timeout Explicit operation timeout
|
51
56
|
# @option options [Boolean] :master_timeout Timeout for connection to master
|
52
|
-
# @return [Hash
|
57
|
+
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
53
58
|
#
|
54
59
|
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/
|
55
60
|
def update_mapping(suffix: index_version, **options)
|
56
61
|
update_mapping!(suffix: suffix, **options)
|
57
62
|
rescue Elasticsearch::Transport::Transport::ServerError
|
58
|
-
|
63
|
+
{ 'errors' => true }
|
59
64
|
end
|
60
65
|
|
61
|
-
|
62
66
|
# Closes the index for read/write operations, updates the index settings, and open it again
|
63
67
|
#
|
64
68
|
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
@@ -78,15 +82,33 @@ module Esse
|
|
78
82
|
#
|
79
83
|
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/
|
80
84
|
def update_settings!(suffix: index_version, **options)
|
81
|
-
name = suffix ? real_index_name(suffix) : index_name
|
82
85
|
response = nil
|
83
86
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
open
|
87
|
+
settings = settings_hash.fetch(Esse::SETTING_ROOT_KEY).transform_keys(&:to_s)
|
88
|
+
settings.delete('number_of_shards') # Can't change number of shards for an index
|
89
|
+
analysis = settings.delete('analysis')
|
90
|
+
|
91
|
+
if settings.any?
|
92
|
+
# When changing the number of replicas the index needs to be open. Changing the number of replicas on a
|
93
|
+
# closed index might prevent the index to be opened correctly again.
|
94
|
+
Esse::Events.instrument('elasticsearch.update_settings') do |payload|
|
95
|
+
payload[:request] = opts = options.merge(index: index_name(suffix: suffix), body: { index: settings })
|
96
|
+
payload[:response] = response = client.indices.put_settings(**opts)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
if analysis
|
101
|
+
# It is also possible to define new analyzers for the index. But it is required to close the
|
102
|
+
# index first and open it after the changes are made.
|
103
|
+
close!(suffix: suffix)
|
104
|
+
begin
|
105
|
+
Esse::Events.instrument('elasticsearch.update_settings') do |payload|
|
106
|
+
payload[:request] = opts = options.merge(index: index_name(suffix: suffix), body: { analysis: analysis })
|
107
|
+
payload[:response] = response = client.indices.put_settings(**opts)
|
108
|
+
end
|
109
|
+
ensure
|
110
|
+
open!(suffix: suffix)
|
111
|
+
end
|
90
112
|
end
|
91
113
|
|
92
114
|
response
|
@@ -105,13 +127,13 @@ module Esse
|
|
105
127
|
# If set to `true` existing settings on an index remain unchanged, the default is `false`
|
106
128
|
# @option options [Time] :master_timeout Specify timeout for connection to master
|
107
129
|
# @option options [Boolean] :flat_settings Return settings in flat format (default: false)
|
108
|
-
# @return [Hash
|
130
|
+
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
109
131
|
#
|
110
132
|
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/
|
111
133
|
def update_settings(suffix: index_version, **options)
|
112
134
|
update_settings!(suffix: suffix, **options)
|
113
135
|
rescue Elasticsearch::Transport::Transport::ServerError
|
114
|
-
|
136
|
+
{ 'errors' => true }
|
115
137
|
end
|
116
138
|
end
|
117
139
|
|
data/lib/esse/backend/index.rb
CHANGED
@@ -10,13 +10,15 @@ module Esse
|
|
10
10
|
require_relative 'index/delete'
|
11
11
|
require_relative 'index/existance'
|
12
12
|
require_relative 'index/update'
|
13
|
+
require_relative 'index/refresh'
|
14
|
+
require_relative 'index/reset'
|
13
15
|
require_relative 'index/documents'
|
14
16
|
require_relative 'index/open'
|
15
17
|
require_relative 'index/close'
|
16
18
|
|
17
19
|
extend Forwardable
|
18
20
|
|
19
|
-
NAMING = %i[
|
21
|
+
NAMING = %i[index_version].freeze
|
20
22
|
DEFINITION = %i[settings_hash mappings_hash].freeze
|
21
23
|
|
22
24
|
def_delegators :@index, :type_hash, *(NAMING + DEFINITION)
|
@@ -27,13 +29,25 @@ module Esse
|
|
27
29
|
|
28
30
|
protected
|
29
31
|
|
30
|
-
def
|
32
|
+
def index_name(suffix: nil)
|
33
|
+
suffix = Hstring.new(suffix).underscore.presence
|
34
|
+
return @index.index_name unless suffix
|
35
|
+
|
36
|
+
[@index.index_name, suffix].join('_')
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_real_index_name(suffix = nil)
|
31
40
|
suffix = Hstring.new(suffix).underscore.presence || index_version || Esse.timestamp
|
32
|
-
|
41
|
+
|
42
|
+
index_name(suffix: suffix)
|
33
43
|
end
|
34
44
|
|
35
45
|
def client
|
36
|
-
|
46
|
+
cluster.client
|
47
|
+
end
|
48
|
+
|
49
|
+
def cluster
|
50
|
+
@index.cluster
|
37
51
|
end
|
38
52
|
end
|
39
53
|
end
|