Class: ElasticGraph::Admin::IndexDefinitionConfigurator::ForIndex
- Inherits:
-
Object
- Object
- ElasticGraph::Admin::IndexDefinitionConfigurator::ForIndex
- Defined in:
- lib/elastic_graph/admin/index_definition_configurator/for_index.rb
Overview
Responsible for managing an index’s configuration, including both mappings and settings.
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Instance Method Summary collapse
-
#configure! ⇒ Object
Attempts to idempotently update the index configuration to the desired configuration exposed by the ‘IndexDefinition` object.
-
#initialize(datastore_client, index, env_agnostic_index_config, output) ⇒ ForIndex
constructor
A new instance of ForIndex.
- #validate ⇒ Object
Constructor Details
#initialize(datastore_client, index, env_agnostic_index_config, output) ⇒ ForIndex
Returns a new instance of ForIndex.
23 24 25 26 27 28 |
# File 'lib/elastic_graph/admin/index_definition_configurator/for_index.rb', line 23 def initialize(datastore_client, index, env_agnostic_index_config, output) @datastore_client = datastore_client @index = index @env_agnostic_index_config = env_agnostic_index_config @reporter = ClusterConfigurator::ActionReporter.new(output) end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
21 22 23 |
# File 'lib/elastic_graph/admin/index_definition_configurator/for_index.rb', line 21 def index @index end |
Instance Method Details
#configure! ⇒ Object
Attempts to idempotently update the index configuration to the desired configuration exposed by the ‘IndexDefinition` object. Based on the configuration of the passed index and the state of the index in the datastore, does one of the following:
- If the index did not already exist: creates the index with the desired mappings and settings.
- If the desired mapping has fewer fields than what is in the index: raises an exception,
because the datastore provides no way to remove fields from a mapping and it would be confusing
for this method to silently ignore the issue.
- If the settings have desired changes: updates the settings, restoring any setting that
no longer has a desired value to its default.
- If the mapping has desired changes: updates the mappings.
Note that any of the writes to the index may fail. There are many things that cannot be changed on an existing index (such as static settings, field mapping types, etc). We do not attempt to validate those things ahead of time and instead rely on the datastore to fail if an invalid operation is attempted.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/elastic_graph/admin/index_definition_configurator/for_index.rb', line 46 def configure! return create_new_index unless index_exists? # Update settings before mappings, to front-load the API call that is more likely to fail. # Our `validate` method guards against mapping changes that are known to be disallowed by # the datastore, but it is much harder to validate that for settings, because there are so # many settings, and there is not clear documentation that outlines all settings, which can # be updated on existing indices, etc. # # If we get a failure, we'd rather it happen before any changes are applied to the index, instead # of applying the mappings and then failing on the settings. update_settings if settings_updates.any? update_mapping if has_mapping_updates? end |
#validate ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/elastic_graph/admin/index_definition_configurator/for_index.rb', line 62 def validate if index_exists? && mapping_type_changes.any? [cannot_modify_mapping_field_type_error] else [] end end |