-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge V2 index/component template mappings in specific manner #55607
Merge V2 index/component template mappings in specific manner #55607
Conversation
This commit changes the way that V2 index, component, and request mappings are merged. Specifically: - Fields are merged in a "replacement" manner, meaning that the entire definition is replaced rather than merging the interior configuration - Mapping metadata (all fields outside of `properties`) are merged recursively. The merging for V1 templates does not change. Relates to elastic#53101
Pinging @elastic/es-core-features (:Core/Features/Indices APIs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks Lee
Left only a minor suggestion
Map<String, Object> innerTemplateNonProperties = new HashMap<>(innerTemplateMapping); | ||
Map<String, Object> maybeProperties = (Map<String, Object>) innerTemplateNonProperties.remove("properties"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
innerTemplateMapping
is only used to initialize innerTemplateNonProperties
Would it make sense for these statements to be executed in reversed order to avoid over allocating innerTemplateNonProperties
just to immediately remove "properties" ?
ie.
Map<String, Object> maybeProperties = (Map<String, Object>) innerTemplateMapping.remove("properties");
Map<String, Object> innerTemplateNonProperties = new HashMap<>(innerTemplateMapping);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ignore this actually, as we'd be modifying a map we didn't create. It's fine as it is
(Some builds were aborted due to Jenkins restart) @elasticmachine run elasticsearch-ci/bwc |
…c#55607) This commit changes the way that V2 index, component, and request mappings are merged. Specifically: - Fields are merged in a "replacement" manner, meaning that the entire definition is replaced rather than merging the interior configuration - Mapping metadata (all fields outside of `properties`) are merged recursively. The merging for V1 templates does not change. Relates to elastic#53101
…55607) (#55619) This commit changes the way that V2 index, component, and request mappings are merged. Specifically: - Fields are merged in a "replacement" manner, meaning that the entire definition is replaced rather than merging the interior configuration - Mapping metadata (all fields outside of `properties`) are merged recursively. The merging for V1 templates does not change. Relates to #53101
Pinging @elastic/es-search (:Search/Mapping) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caught my eye as I was looking at open PRs. The current behavior is a bit unexpected to me -- we only replace the top-level keys, as opposed to the field definitions. For example, my understanding is that merging these two mappings
{
"properties": {
"object": {
"foo": { "type": "keyword" }
}
}
{
"properties": {
"object": {
"bar": { "type": "keyword" }
}
}
will currently result in
{
"properties": {
"object": {
"bar": { "type": "keyword" }
}
}
Is this the intended behavior? It seems like we would want to be able to introduce new fields, even if they shared a parent object with an existing field.
I'm also wondering if we want to merge all the non-properties blocks recursively. For example in #29200 we discussed that we'd like dynamic templates to replace existing ones with the same name.
@jpountz had a good observation about dots in field names. Given a low-priority template with an object field To me this produces pretty subtle behavior -- sometimes top-level fields are overwritten, sometimes they are not. |
This commit changes the merge strategy introduced in elastic#55607 and elastic#55982. Instead of overwriting these fields, we now prevent them from being merged with an exception when a user attempts to overwrite a field. As part of this, a more robust validation has been added. The existing validation checked whether templates (composable and component) were valid on their own, this new validation now checks that the composite template (mappings/settings/aliases) is valid. This means that when a composable template is added or updated, we confirm that it is valid with its component pieces. When a component template is updated we ensure that all composable templates that make use of the component template continue to be valid before allowing the component template to be updated. This change also necessitated changes in the tests, however, I have left tests that exercise mapping merging with nested object fields as `@AwaitsFix`, as we intend to change the behavior soon to allow merging in a recursive-with-replacement fashion (see: elastic#57393). I have added tests that check the new disallowing behavior in the meantime.
) * Disallow merging existing mapping field definitions in templates This commit changes the merge strategy introduced in #55607 and #55982. Instead of overwriting these fields, we now prevent them from being merged with an exception when a user attempts to overwrite a field. As part of this, a more robust validation has been added. The existing validation checked whether templates (composable and component) were valid on their own, this new validation now checks that the composite template (mappings/settings/aliases) is valid. This means that when a composable template is added or updated, we confirm that it is valid with its component pieces. When a component template is updated we ensure that all composable templates that make use of the component template continue to be valid before allowing the component template to be updated. This change also necessitated changes in the tests, however, I have left tests that exercise mapping merging with nested object fields as `@AwaitsFix`, as we intend to change the behavior soon to allow merging in a recursive-with-replacement fashion (see: #57393). I have added tests that check the new disallowing behavior in the meantime. * Use functional instead of imperative prefix collection * Use IndexService.withTempIndexService * Rename tests * Fix tests Co-authored-by: Elastic Machine <[email protected]>
…stic#57701) * Disallow merging existing mapping field definitions in templates This commit changes the merge strategy introduced in elastic#55607 and elastic#55982. Instead of overwriting these fields, we now prevent them from being merged with an exception when a user attempts to overwrite a field. As part of this, a more robust validation has been added. The existing validation checked whether templates (composable and component) were valid on their own, this new validation now checks that the composite template (mappings/settings/aliases) is valid. This means that when a composable template is added or updated, we confirm that it is valid with its component pieces. When a component template is updated we ensure that all composable templates that make use of the component template continue to be valid before allowing the component template to be updated. This change also necessitated changes in the tests, however, I have left tests that exercise mapping merging with nested object fields as `@AwaitsFix`, as we intend to change the behavior soon to allow merging in a recursive-with-replacement fashion (see: elastic#57393). I have added tests that check the new disallowing behavior in the meantime. * Use functional instead of imperative prefix collection * Use IndexService.withTempIndexService * Rename tests * Fix tests Co-authored-by: Elastic Machine <[email protected]>
…stic#57701) * Disallow merging existing mapping field definitions in templates This commit changes the merge strategy introduced in elastic#55607 and elastic#55982. Instead of overwriting these fields, we now prevent them from being merged with an exception when a user attempts to overwrite a field. As part of this, a more robust validation has been added. The existing validation checked whether templates (composable and component) were valid on their own, this new validation now checks that the composite template (mappings/settings/aliases) is valid. This means that when a composable template is added or updated, we confirm that it is valid with its component pieces. When a component template is updated we ensure that all composable templates that make use of the component template continue to be valid before allowing the component template to be updated. This change also necessitated changes in the tests, however, I have left tests that exercise mapping merging with nested object fields as `@AwaitsFix`, as we intend to change the behavior soon to allow merging in a recursive-with-replacement fashion (see: elastic#57393). I have added tests that check the new disallowing behavior in the meantime. * Use functional instead of imperative prefix collection * Use IndexService.withTempIndexService * Rename tests * Fix tests Co-authored-by: Elastic Machine <[email protected]>
This commit changes the way that V2 index, component, and request mappings are merged. Specifically:
than merging the interior configuration
properties
) are merged recursively.The merging for V1 templates does not change.
Relates to #53101