Skip to content

Commit f4c3b72

Browse files
committed
Document why index templates drop removed fields
Dropping a field from an index template is a real datastore-state change with operational risk (new rollover indices are auto-created from the template with dynamic: strict mappings), and we previously had a near-SEV from dropping a template field while old indexers still published it. Re-record that history and the required schema evolution workflow at the decision point, since this PR removes the merge_properties guard that previously preserved template fields.
1 parent fcba5e2 commit f4c3b72

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

elasticgraph-admin/lib/elastic_graph/admin/index_definition_configurator/for_index_template.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def initialize(datastore_client, index_template, env_agnostic_index_config_paren
3737
#
3838
# - If the index did not already exist: creates the index with the desired mappings and settings.
3939
# - If the desired mapping has fewer fields than what is in the index template: updates the template
40-
# to drop those fields. Related concrete indices preserve their existing fields because the datastore
41-
# provides no way to remove fields from index mappings.
40+
# to drop those fields (see `put_index_template` for the operational caveats of dropping fields).
41+
# Related concrete indices preserve their existing fields because the datastore provides no way
42+
# to remove fields from index mappings.
4243
# - If the settings have desired changes: updates the settings, restoring any setting that
4344
# no longer has a desired value to its default.
4445
# - If the mapping has desired changes: updates the mappings.
@@ -66,6 +67,24 @@ def validate
6667

6768
private
6869

70+
# Creates or updates the index template to exactly match the desired configuration -- including
71+
# dropping any fields that have been removed from the schema. This intentionally differs from how
72+
# we treat concrete indices (see `MappingUpdate.merge_existing_fields_into`): the datastore does
73+
# not support removing fields from an existing index, so we preserve them there, but it does allow
74+
# template fields to be dropped, and dropping them keeps templates from accumulating stale fields
75+
# forever.
76+
#
77+
# Dropping a template field is not risk-free, though. New rollover indices are auto-created from
78+
# the template at indexing time, and ElasticGraph mappings use `dynamic: strict`--so once a field
79+
# is dropped from the template, any indexer that still publishes that field will fail to index
80+
# documents into newly created indices. We have previously had a near-SEV from dropping a template
81+
# field while deployed indexers were still running an old version of the code that used it, and for
82+
# a long time this logic preserved existing template fields to guard against a repeat. That guard
83+
# came at the cost of never being able to garbage-collect stale template fields, so we now drop
84+
# them and instead rely on the schema evolution workflow: only remove a field from the schema once
85+
# no deployed indexer still publishes it (and no old events containing it will be replayed). Any
86+
# dropped fields show up as deletions in the diff reported below, giving operators a chance to
87+
# catch a premature removal.
6988
def put_index_template
7089
action_description = if index_template_exists?
7190
"Updated index template: `#{@index_template.name}`:\n#{config_diff}"

0 commit comments

Comments
 (0)