Fix elasticsearch2 schema load on ES7+/8 mapping metadata keys#7762
Open
tostavio wants to merge 5 commits into
Open
Fix elasticsearch2 schema load on ES7+/8 mapping metadata keys#7762tostavio wants to merge 5 commits into
tostavio wants to merge 5 commits into
Conversation
`_parse_mappings` iterates the keys under `mappings` assuming each is a
mapping type whose value is a dict containing `properties`. On Elasticsearch
7+/8 there are no mapping types: `mappings` holds metadata keys such as
`dynamic` (a bool) and `dynamic_templates` (a list) alongside `properties`.
Indexing those with `["properties"]` raises `TypeError`, which the existing
`except KeyError` does not catch, so `get_schema` fails for the whole data
source ("Schema refresh failed") whenever any visible index carries those
keys.
Catch `TypeError` as well so the loop falls back to reading
`mappings["properties"]` directly, which is the correct ES7+/8 shape.
Adds a regression test covering a mapping with `dynamic` and
`dynamic_templates` next to `properties`.
tostavio
force-pushed
the
fix/es2-mappings-typeerror-dynamic
branch
from
June 25, 2026 16:34
b3df6bd to
5d27a82
Compare
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.
What type of PR is this?
Description
This pull request fixes the
elasticsearch2query runner, which fails to load the schema and shows "Schema refresh failed" against Elasticsearch 7.x and 8.x.ElasticSearch2._parse_mappingsiterates over the keys undermappingsand assumes that each one is a mapping type whose value is a dictionary containingproperties:This structure only held for Elasticsearch 6.x and earlier. Since mapping types were removed in Elasticsearch 7, the
_mappingsresponse places the metadata keys directly undermappings. For example,dynamic, which is a boolean, anddynamic_templates, which is a list, now appear alongsideproperties:{ "my-index": { "mappings": { "dynamic": false, "dynamic_templates": [ { "strings": { "mapping": { "type": "keyword" } } } ], "properties": { "sku": { "type": "keyword" } } } } }When the loop reaches
m == "dynamic", it evaluatesmappings["dynamic"]["properties"], which isFalse["properties"], and this raisesTypeError: 'bool' object is not subscriptable. Thedynamic_templateskey, which is a list, fails in the same way. The surroundingexcept KeyErrordoes not catchTypeError, soget_schemaaborts for the entire data source whenever any visible index carries those keys. This is common with APM and Kibana system indices, such as.internal.alerts-*,.kibana-*,.ds-traces-apm-*, and.ds-metrics-apm-*, and with user indices that setdynamicordynamic_templates.Fix
Catch
TypeErroralongsideKeyError, so that the loop falls back to readingmappings["properties"]directly, which is the correct shape for Elasticsearch 7 and 8:Queries are not affected, because they go through
/{index}/_search; only the schema parsing was broken. The change is compatible with Elasticsearch 7.x and 8.x.How is this tested?
I added
TestElasticSearch.test_parse_mappings_with_dynamic_keys, which parses a mapping that containsdynamicanddynamic_templatesnext topropertiesand asserts that the field types are extracted. Without the fix this test raisesTypeError; with the fix, the schema is parsed correctly.Related Tickets & Documents
Closes #7761.
This pull request is also related to #5545, which reports the same user-facing symptom ("Schema refresh failed") against the older
elasticsearchrunner. This change addresses theelasticsearch2runner specifically.Mobile & Desktop Screenshots/Recordings (if there are UI changes)
N/A. This is a backend-only change, with no UI.