Module: ElasticGraph::DatastoreCore::IndexConfigNormalizer
- Defined in:
- lib/elastic_graph/datastore_core/index_config_normalizer.rb
Constant Summary collapse
- READ_ONLY_SETTINGS =
These are settings that the datastore exposes when you fetch an index, but that you can never set. We need to ignore them when figuring out what settings to update.
Note: ‘index.routing.allocation.include._tier_preference` is not a read-only setting, but we want to treat it as one, because (1) Elasticsearch 7.10+ sets it and (2) we do not want to ever write it at this time.
Note: ‘index.history.uuid` is a weird setting that sometimes shows up in managed AWS OpenSearch clusters, but only on some indices. It’s not documented and we don’t want to mess with it here, so we want to treat it as a read only setting.
%w[ index.creation_date index.history.uuid index.provided_name index.replication.type index.routing.allocation.include._tier_preference index.uuid index.version.created index.version.upgraded ]
Class Method Summary collapse
-
.normalize(index_config) ⇒ Object
Normalizes the provided index configuration so that it is in a stable form that we can compare to what the datastore returns when we query it for the configuration of an index.
- .normalize_mappings(mappings) ⇒ Object
- .normalize_settings(settings) ⇒ Object
Class Method Details
.normalize(index_config) ⇒ Object
Normalizes the provided index configuration so that it is in a stable form that we can compare to what the datastore returns when we query it for the configuration of an index. This includes:
-
Dropping read-only settings that we never interact with but that the datastore automatically sets on an index. Omitting them makes it easier for us to compare our desired configuration to what is in the datastore.
-
Converting setting values to a normalized string form. The datastore oddly returns setting values as strings (e.g. ‘“false”` or `“7”` instead of `false` or `7`), so this matches that behavior.
-
Drops ‘type: object` from a mapping when there are `properties` because the datastore omits it in that situation, treating it as the default type.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/elastic_graph/datastore_core/index_config_normalizer.rb', line 42 def self.normalize(index_config) if (settings = index_config["settings"]) index_config = index_config.merge("settings" => normalize_settings(settings)) end if (mappings = index_config["mappings"]) index_config = index_config.merge("mappings" => normalize_mappings(mappings)) end index_config end |
.normalize_mappings(mappings) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/elastic_graph/datastore_core/index_config_normalizer.rb', line 54 def self.normalize_mappings(mappings) return mappings unless (properties = mappings["properties"]) mappings = mappings.except("type") if mappings["type"] == "object" mappings.merge("properties" => properties.transform_values { |prop| normalize_mappings(prop) }) end |
.normalize_settings(settings) ⇒ Object
61 62 63 64 65 |
# File 'lib/elastic_graph/datastore_core/index_config_normalizer.rb', line 61 def self.normalize_settings(settings) settings .except(*READ_ONLY_SETTINGS) .to_h { |name, value| [name, normalize_setting_value(value)] } end |