-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Disallow merging existing mapping field definitions in templates #57701
Disallow merging existing mapping field definitions in templates #57701
Conversation
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.
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.
Thanks for working on this Lee! I left a few mostly minor comments
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java
Show resolved
Hide resolved
/** | ||
* Given a state and a composable template, validate that the final composite template | ||
* generated by the composable template and all of its component templates contains valid | ||
* settings, mappings, and aliases. | ||
*/ | ||
private static void validateCompositeTemplate(final ClusterState state, |
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.
the composite
term is a bit confusing (at least for me) - we have composable templates
so composite template
made me think of a possible v3
template of sorts that might combine other templates. Would it make sense to reuse resolve(d)
for the final configuration of a composable template? ie. validateResolvedComposableTemplate
? resolveAndValidateComposableTemplate
?
What do you think?
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.
I dunno, I didn't think they were too different, I wanted to treat "resolved" as pertaining to a particular index, so I think the current name isn't too bad.
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java
Outdated
Show resolved
Hide resolved
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 for iterating on this Lee
@elasticmachine update branch |
…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]>
#57701) (#57823) Co-authored-by: Elastic Machine <[email protected]>
@dakrone and I discussed offline and determined that we should also throw an error when a metadata key is specified twice (like |
In elastic#57701 we changed mappings merging so that duplicate fields specified in mappings caused an exception during validation. This change makes the same exception thrown when metadata fields are duplicated. This will allow us to be strict currently with plans to make the merging more fine-grained in a later release.
In elastic#57701 we changed mappings merging so that duplicate fields specified in mappings caused an exception during validation. This change makes the same exception thrown when metadata fields are duplicated. This will allow us to be strict currently with plans to make the merging more fine-grained in a later release.
In elastic#57701 we changed mappings merging so that duplicate fields specified in mappings caused an exception during validation. This change makes the same exception thrown when metadata fields are duplicated. This will allow us to be strict currently with plans to make the merging more fine-grained in a later release.
…mplates (#57835) In #57701 we changed mappings merging so that duplicate fields specified in mappings caused an exception during validation. This change makes the same exception thrown when metadata fields are duplicated. This will allow us to be strict currently with plans to make the merging more fine-grained in a later release.
In #57701 we changed mappings merging so that duplicate fields specified in mappings caused an exception during validation. This change makes the same exception thrown when metadata fields are duplicated. This will allow us to be strict currently with plans to make the merging more fine-grained in a later release.
This is a backport of #57835 In #57701 we changed mappings merging so that duplicate fields specified in mappings caused an exception during validation. This change makes the same exception thrown when metadata fields are duplicated. This will allow us to be strict currently with plans to make the merging more fine-grained in a later release.
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 allowmerging in a recursive-with-replacement fashion (see: #57393). I have added tests that check the new
disallowing behavior in the meantime.