esse 0.0.3 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/exec/esse +3 -1
  3. data/lib/esse/backend/index/aliases.rb +8 -4
  4. data/lib/esse/backend/index/close.rb +6 -5
  5. data/lib/esse/backend/index/create.rb +20 -9
  6. data/lib/esse/backend/index/delete.rb +15 -14
  7. data/lib/esse/backend/index/documents.rb +2 -2
  8. data/lib/esse/backend/index/existance.rb +2 -3
  9. data/lib/esse/backend/index/open.rb +6 -5
  10. data/lib/esse/backend/index/refresh.rb +43 -0
  11. data/lib/esse/backend/index/reset.rb +33 -0
  12. data/lib/esse/backend/index/update.rb +37 -15
  13. data/lib/esse/backend/index.rb +18 -4
  14. data/lib/esse/backend/index_type/documents.rb +53 -42
  15. data/lib/esse/backend/index_type.rb +7 -2
  16. data/lib/esse/cli/event_listener.rb +87 -0
  17. data/lib/esse/cli/generate.rb +9 -4
  18. data/lib/esse/cli/index/base_operation.rb +76 -0
  19. data/lib/esse/cli/index/close.rb +26 -0
  20. data/lib/esse/cli/index/create.rb +26 -0
  21. data/lib/esse/cli/index/delete.rb +26 -0
  22. data/lib/esse/cli/index/import.rb +26 -0
  23. data/lib/esse/cli/index/open.rb +26 -0
  24. data/lib/esse/cli/index/reset.rb +26 -0
  25. data/lib/esse/cli/index/update_aliases.rb +32 -0
  26. data/lib/esse/cli/index/update_mapping.rb +33 -0
  27. data/lib/esse/cli/index/update_settings.rb +26 -0
  28. data/lib/esse/cli/index.rb +78 -2
  29. data/lib/esse/cli/templates/config.rb.erb +20 -0
  30. data/lib/esse/cli/templates/index.rb.erb +76 -11
  31. data/lib/esse/cli/templates/type_collection.rb.erb +41 -0
  32. data/lib/esse/cli/templates/{mappings.json → type_mappings.json} +0 -0
  33. data/lib/esse/cli/templates/type_serializer.rb.erb +23 -0
  34. data/lib/esse/cli.rb +75 -3
  35. data/lib/esse/cluster.rb +22 -6
  36. data/lib/esse/config.rb +39 -5
  37. data/lib/esse/core.rb +18 -36
  38. data/lib/esse/errors.rb +47 -0
  39. data/lib/esse/events/bus.rb +103 -0
  40. data/lib/esse/events/event.rb +64 -0
  41. data/lib/esse/events/publisher.rb +119 -0
  42. data/lib/esse/events.rb +49 -0
  43. data/lib/esse/index/backend.rb +2 -1
  44. data/lib/esse/index/base.rb +4 -6
  45. data/lib/esse/index/mappings.rb +2 -3
  46. data/lib/esse/index/settings.rb +7 -8
  47. data/lib/esse/index.rb +2 -1
  48. data/lib/esse/index_mapping.rb +2 -2
  49. data/lib/esse/index_setting.rb +8 -4
  50. data/lib/esse/index_type/actions.rb +2 -1
  51. data/lib/esse/index_type/backend.rb +2 -1
  52. data/lib/esse/index_type/mappings.rb +2 -2
  53. data/lib/esse/index_type.rb +6 -1
  54. data/lib/esse/logging.rb +19 -0
  55. data/lib/esse/object_document_mapper.rb +96 -0
  56. data/lib/esse/primitives/hash_utils.rb +40 -0
  57. data/lib/esse/primitives/hstring.rb +4 -3
  58. data/lib/esse/primitives/output.rb +64 -0
  59. data/lib/esse/primitives.rb +1 -0
  60. data/lib/esse/template_loader.rb +1 -1
  61. data/lib/esse/version.rb +1 -1
  62. data/lib/esse.rb +12 -3
  63. metadata +124 -21
  64. data/.gitignore +0 -12
  65. data/.rubocop.yml +0 -128
  66. data/CHANGELOG.md +0 -0
  67. data/Gemfile +0 -7
  68. data/Gemfile.lock +0 -60
  69. data/LICENSE.txt +0 -21
  70. data/README.md +0 -52
  71. data/Rakefile +0 -4
  72. data/bin/console +0 -22
  73. data/bin/setup +0 -8
  74. data/esse.gemspec +0 -39
  75. data/lib/esse/cli/templates/serializer.rb.erb +0 -14
  76. data/lib/esse/index_type/serializer.rb +0 -87
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d7f91a4ecb008fe3d8849175cb6f1bb08605d56432b7bc7f52ca9df0c55e77e
4
- data.tar.gz: a9b4143597ca2ca571360814b381e8398bd3ac8b45134fc5b3086dfc8a33f0a1
3
+ metadata.gz: 4dff3560f305debeee691263267e43df0e70a17591f6ecfc897025a5c07ada8a
4
+ data.tar.gz: a8ba452b0bfc81210f104293f852ecacaef585ea23b2e8f24177197fa2555e69
5
5
  SHA512:
6
- metadata.gz: ef25dc5238beea72d67eeaf146dad16184cd8d78c76fc84516154e8ddd5cb93f2c5f1fd84574359147d6428dbdb1d25f037d0dce004f79e4e22cbbf1dcc2a30b
7
- data.tar.gz: 6c5237fc9f5b59376ef6e948132c5a78200f4f849acab591ba603b3c5173d95c6179dfec3844331a6ba30f41ae519515b12c3f3396d80e4bff5dd3445525faad
6
+ metadata.gz: 73bfc1a130c18df947cd02120087eed2b571fa174b84009b687dc0e343697aec1a1a20ae00eb0fc8465a9ad603d95318c02d324b98fe811baddc0b08d3533e28
7
+ data.tar.gz: 160aaf9fdef9da05108c1e966cfc03a45f9357aeb4682d551458546f66dc067d0585e52f0836aa0b4ee8fb5d634d3b705bced6340e91a99013d571fcded5f574
data/exec/esse CHANGED
@@ -6,4 +6,6 @@ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
6
6
  require 'esse'
7
7
  require 'esse/cli'
8
8
 
9
- Esse::CLI.start(ARGV)
9
+ Esse::CLI.with_friendly_errors do
10
+ Esse::CLI.start(ARGV)
11
+ end
@@ -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: real_index_name(suffix), alias: index_name } }
47
+ { add: {index: build_real_index_name(suffix), alias: index_name } }
48
48
  ],
49
49
  }
50
- client.indices.update_aliases(options)
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, false] the elasticsearch response, or false in case of failure
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
- false
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
- name = suffix ? real_index_name(suffix) : index_name
25
-
26
- client.indices.close(options.merge(index: name))
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, false] the elasticsearch response, or false in case of failure
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
- false
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.backend.create_index # creates index named `<prefix_>users_<suffix|index_version|timestamp>`
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, false] the elasticsearch response or false in case of unsuccessful creation.
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: nil, **options)
22
+ def create_index(suffix: index_version, **options)
23
23
  create_index!(suffix: suffix, **options)
24
24
  rescue Elasticsearch::Transport::Transport::Errors::BadRequest
25
- false
25
+ { 'errors' => true }
26
26
  end
27
27
 
28
28
  # Creates index and applies mappings and settings.
29
29
  #
30
- # UsersIndex.backend.create_index! # creates index named `<prefix_>users_<suffix|index_version|timestamp>`
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: nil, **options)
46
+ def create_index!(suffix: index_version, **options)
41
47
  options = DEFAULT_OPTIONS.merge(options)
42
- name = real_index_name(suffix)
48
+ name = build_real_index_name(suffix)
43
49
  definition = [settings_hash, mappings_hash].reduce(&:merge)
44
50
 
45
- if options[:alias] && name != index_name
51
+ if options.delete(:alias) && name != index_name
46
52
  definition[:aliases] = { index_name => {} }
47
53
  end
48
54
 
49
- client.indices.create(index: name, body: definition)
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.backend.delete_index! # deletes `<prefix_>users<_suffix|_index_version|_timestamp>` index
9
+ # UsersIndex.elasticsearch.delete_index! # deletes `<prefix_>users<_suffix|_index_version|_timestamp>` index
10
10
  #
11
- # @param options [Hash] Options hash
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
- name = suffix ? real_index_name(suffix) : index_name
17
-
18
- client.indices.delete(index: name)
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.backend.delete_index # deletes `<prefix_>users<_suffix|_index_version|_timestamp>` index
25
+ # UsersIndex.elasticsearch.delete_index # deletes `<prefix_>users<_suffix|_index_version|_timestamp>` index
24
26
  #
25
- # @param options [Hash] Options hash
26
- # @option [String] :suffix The index suffix. Use nil if you want to delete the current index.
27
- # @return [Hash, false] elasticsearch response, of false in case of error.
28
- def delete_index(suffix: index_version)
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
- false
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.backend.import!(**options)
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.backend.import(**options)
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.backend.exist? #=> true
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
- name = suffix ? real_index_name(suffix) : index_name
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
- name = suffix ? real_index_name(suffix) : index_name
25
-
26
- client.indices.open(options.merge(index: name))
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, false] the elasticsearch response, or false in case of failure
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
- false
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
- name = suffix ? real_index_name(suffix) : index_name
31
-
32
- client.indices.put_mapping(options.merge(index: name, body: mappings_hash.fetch(Esse::MAPPING_ROOT_KEY)))
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, false] the elasticsearch response, or false in case of failure
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
- false
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
- close!(suffix: suffix)
85
- begin
86
- body = settings_hash(cluster_settings: false).fetch(Esse::SETTING_ROOT_KEY)
87
- response = client.indices.put_settings(options.merge(index: name, body: body))
88
- ensure
89
- open!(suffix: suffix)
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, false] the elasticsearch response, false in case of failure
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
- false
136
+ { 'errors' => true }
115
137
  end
116
138
  end
117
139
 
@@ -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[index_name index_version].freeze
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 real_index_name(suffix = nil)
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
- [index_name, suffix].compact.join('_')
41
+
42
+ index_name(suffix: suffix)
33
43
  end
34
44
 
35
45
  def client
36
- @index.cluster.client
46
+ cluster.client
47
+ end
48
+
49
+ def cluster
50
+ @index.cluster
37
51
  end
38
52
  end
39
53
  end