Drop index template fields once the schema no longer references them#1303
Open
jwils wants to merge 2 commits into
Open
Drop index template fields once the schema no longer references them#1303jwils wants to merge 2 commits into
jwils wants to merge 2 commits into
Conversation
jwils
requested review from
BrianSigafoos-SQ,
bsorbo,
ellisandrews-toast,
jwondrusch,
marcdaniels-toast,
myronmarston and
rossroberts-toast
as code owners
July 8, 2026 21:23
jwils
force-pushed
the
joshuaw/hide-delete-changes-admin-lambda
branch
from
July 8, 2026 21:33
2b3c876 to
bc2d25d
Compare
jwils
force-pushed
the
joshuaw/drop-unreferenced-template-fields
branch
from
July 8, 2026 21:38
c507876 to
5d8214f
Compare
jwils
added a commit
that referenced
this pull request
Jul 9, 2026
## Summary - Move mapping-removal noise handling into `elasticgraph-admin` so all admin users benefit. - Preserve current mapping fields in index update payloads and diffs--for concrete indices *and* index templates--hiding unsupported/unsafe field removals while still showing new fields and mapping parameter changes. - Keep settings diffs complete, and report new index templates as created instead of dumping the full config diff. This is purely an output improvement: no behavior changes. Index templates keep preserving fields that have been removed from the schema (as they always have); the removals just no longer clutter every admin run's diff. Actually dropping stale template fields safely is implemented separately in the stacked PR #1303, per review feedback. ## Context Mapping removals are unsupported by Elasticsearch/OpenSearch concrete indices, so showing removed fields every admin run just makes the diffs harder to read. Index templates technically allow field removal, but dropping a field that an older deployed indexer can still write causes indexing failures on new rollover indices (mappings are `dynamic: strict`), so templates keep their existing fields and the removals are likewise hidden from the diff output. This addresses #766 and the review feedback to improve `elasticgraph-admin` directly instead of adding an `elasticgraph-admin_lambda` opt-in. ## Verification - `script/lint` - `script/spellcheck` - `script/type_check` - `script/quick_build`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1206.
Why
Index templates preserve every field forever (a guard added after a near-SEV caused by dropping a template field while deployed indexers still wrote it), so fields removed from the schema accumulate as stale template cruft with no garbage-collection path.
This implements the approach proposed in the #1206 review discussion: preserve a template field as long as it exists in some form in the schema definition--as a current field, a
renamed_fromfield, or adeleted_field--and drop it only once the last reference is removed.That rule avoids the SEV footgun without relying on vigilant artifact-diff review:
eg-schema_defrequires adeleted_field/renamed_fromdeclaration for as long as any versioned JSON schema references the field, and warns once the declaration becomes unnecessary. By the time an operator can remove the declaration, no JSON schema version references the field--so every deployed indexer drops it from old events, and no replayable event can produce it.How
RuntimeMetadata::IndexDefinitiongainsfield_paths_protected_from_removal: full index field paths derived fromdeleted_fieldandrenamed_fromdeclarations on the indexed type and all embedded object types (union/interface subtypes included). Empty lists are pruned from dumped YAML, so existing schema artifacts do not change.DatastoreCore::IndexDefinitionexposes it like the other runtime metadata attributes.MappingUpdate.build_mapping_updateaccepts an optionalprotected_field_pathsset: when provided, a field missing from the desired mapping is preserved only if its path (or a descendant's path) is protected; other missing fields drop out of the built update.ForIndexTemplatepasses the protected set; concrete indices continue to preserve everything (the datastore provides no way to remove their fields).Dropped fields are called out explicitly in the admin output, in addition to appearing as deletions in the diff:
Known limitation
A deleted field's
name_in_indexis not recorded anywhere (deleted_fieldonly captures the GraphQL field name, and old versioned JSON schemas have theirElasticGraphmetadata nulled on deletion), so protection matches template fields by the declared name. A removed field that used a customname_in_indexwould not match its template field, which would therefore be dropped while still referenced. If we want to close that gap,deleted_fieldcould optionally acceptname_in_index:(or we could capture it from the prior artifacts at dump time)--happy to tackle that here or in a follow-up.Verification
script/lintscript/spellcheckscript/type_checkscript/quick_buildbundle exec rake schema_artifacts:dumpconfirms no artifact changes for schemas without declarations