esse 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc6a554b787bfb51e5568bd590790171cc88ad8c5ce432e1de2c3ef68a5d1def
4
- data.tar.gz: cac82a25d6e8dd6dad3667a734d58be098f4b7020db76472359f7bdb4fe2067c
3
+ metadata.gz: 9fc6f63594da661b35bc22ab0c83655ded02b8ebe2e20ec5612a0927934156e9
4
+ data.tar.gz: c46f9a70e262d40a9c60c7ce72be3e3b816d18c536f6e3fe770bd06c06c5f57b
5
5
  SHA512:
6
- metadata.gz: f26afad34715ed37cec3f1d1cad11ca6e05d2921a6f31884d9ea9f1136ef239ba7661e29796c37abf69ea19aa5f5407884cf88b108bbfa211e5639e371d492ed
7
- data.tar.gz: 13b1921d85723d3c33bacc54c7bcf95885a196c3a62c095a5ea3be5a5d5061b8cd4eb8fbb1bdbf1bb91c141ed4457f9a1baab5ec121dd7e4f4dc1c1c423277d2
6
+ metadata.gz: 8525a1ba74d9452163e87e1acf1bf621654f2bb8b9a7811e6eca94fc452c47f9255808b2c45be701112be085f8d3176243a685fcfb6647a8e9845699a727911d
7
+ data.tar.gz: 3d0be64e631a47c07758341b34fc86eedffd76bbd12c4734016d9303c256d9c8470929fc564bdace28bb21f072e44d0193cbee06e8e808675a695b46aac92c38
@@ -4,29 +4,21 @@ module Esse
4
4
  # https://github.com/elastic/elasticsearch-ruby/blob/master/elasticsearch-api/lib/elasticsearch/api/actions/indices/put_settings.rb
5
5
  class Index
6
6
  module ClassMethods
7
- # Elasticsearch supports passing index.* related settings directly in the body of the request.
8
- # We are moving it to the index key to make it more explicit and to be the source-of-truth when merging settings.
9
- # So the settings `{ number_of_shards: 1 }` will be transformed to `{ index: { number_of_shards: 1 } }`
10
- INDEX_SIMPLIFIED_SETTINGS = %i[
11
- number_of_shards
12
- number_of_replicas
13
- refresh_interval
14
- mapping
15
- ].freeze
7
+ # Backwards-compatible alias. The canonical list now lives on
8
+ # +Esse::IndexSetting::INDEX_SIMPLIFIED_SETTINGS+ so that the merge
9
+ # logic and the simplified-key promotion stay in sync.
10
+ INDEX_SIMPLIFIED_SETTINGS = Esse::IndexSetting::INDEX_SIMPLIFIED_SETTINGS
16
11
 
17
12
  def settings_hash(settings: nil)
18
- hash = setting.body
19
- values = (hash.key?(Esse::SETTING_ROOT_KEY) ? hash[Esse::SETTING_ROOT_KEY] : hash)
20
- values = HashUtils.explode_keys(values)
21
- if settings.is_a?(Hash)
22
- values = HashUtils.deep_merge(values, HashUtils.explode_keys(settings))
23
- end
24
- INDEX_SIMPLIFIED_SETTINGS.each do |key|
25
- next unless values.key?(key)
26
- value = values.delete(key)
27
- next if value.nil?
13
+ # Normalize each side (global vs local) separately before merging so
14
+ # a flat global key (e.g. top-level :number_of_shards) cannot clobber
15
+ # an explicit nested local value (e.g. :index => { :number_of_shards => 8 }).
16
+ global = Esse::IndexSetting.normalize(setting.globals)
17
+ local = Esse::IndexSetting.normalize(setting.to_h)
18
+ values = HashUtils.deep_merge(global, local)
28
19
 
29
- (values[:index] ||= {}).merge!(key => value)
20
+ if settings.is_a?(Hash)
21
+ values = HashUtils.deep_merge(values, Esse::IndexSetting.normalize(settings))
30
22
  end
31
23
 
32
24
  if values[:index].is_a?(Hash)
@@ -3,6 +3,17 @@
3
3
  module Esse
4
4
  # https://www.elastic.co/guide/en/elasticsearch/reference/1.7/indices.html
5
5
  class IndexSetting
6
+ # Top-level keys that Elasticsearch/OpenSearch accept either flat or nested
7
+ # under `index:`. We always promote them to the nested form so that values
8
+ # from different sources (cluster globals vs per-index template) merge
9
+ # predictably regardless of which form each side was authored in.
10
+ INDEX_SIMPLIFIED_SETTINGS = %i[
11
+ number_of_shards
12
+ number_of_replicas
13
+ refresh_interval
14
+ mapping
15
+ ].freeze
16
+
6
17
  # @param [Hash] options
7
18
  # @option options [Proc] :globals A proc that will be called to load global settings
8
19
  # @option options [Array] :paths A list of paths to load settings from
@@ -35,6 +46,38 @@ module Esse
35
46
  HashUtils.deep_merge(global, local)
36
47
  end
37
48
 
49
+ # Returns the raw (unsymbolized) global settings as supplied by the
50
+ # +globals+ proc. Public so that callers like
51
+ # +Esse::Index.settings_hash+ can normalize it independently before
52
+ # merging it with the local template — preventing a flat global value
53
+ # from clobbering a nested local value once both are merged.
54
+ def globals
55
+ @globals.call || {}
56
+ end
57
+
58
+ # Normalize a settings hash by:
59
+ # * symbolizing keys
60
+ # * stripping the `:settings` root if present
61
+ # * exploding dotted keys ('index.number_of_replicas' -> { index: { number_of_replicas: ... } })
62
+ # * promoting simplified flat keys (number_of_shards, etc.) into the
63
+ # nested `:index` form, preserving any value already present under
64
+ # `:index` (we never overwrite an explicit nested setting with a
65
+ # flat value from the same source).
66
+ def self.normalize(hash)
67
+ values = HashUtils.deep_transform_keys(hash || {}, &:to_sym)
68
+ values = values[Esse::SETTING_ROOT_KEY] if values.key?(Esse::SETTING_ROOT_KEY)
69
+ values = HashUtils.explode_keys(values)
70
+ INDEX_SIMPLIFIED_SETTINGS.each do |key|
71
+ next unless values.key?(key)
72
+ value = values.delete(key)
73
+ next if value.nil?
74
+
75
+ values[:index] ||= {}
76
+ values[:index][key] = value unless values[:index].key?(key)
77
+ end
78
+ values
79
+ end
80
+
38
81
  protected
39
82
 
40
83
  def from_template
data/lib/esse/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Esse
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
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.4.0
4
+ version: 0.4.1
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: 2026-03-18 00:00:00.000000000 Z
11
+ date: 2026-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json