ITV2: disallow duplicate dynamic templates#56291
Conversation
Dynamic templates can contain multiple templates with the same name. This commit changes the way V2 index templates mappings are resolved to add deduplication of dynamic templates when resolving the mappings, by having the last dynamic templates override the ones defined with the same name earlier in the `dynamic_templates` array.
|
Pinging @elastic/es-core-features (:Core/Features/Indices APIs) |
|
@andreidan can you add a test that component templates merge their dynamic templates correctly? I think because we merge the XContent maps prior to the dedupe it is possible to end up with an invalid dynamic template if you have two component templates that each define a dynamic template with the same name but different configurations that, when merged, make the template invalid. |
|
@dakrone thanks for the suggestion on the component templates merging. Great shout on testing that as you were right and we are merging the Maps so, even though we dedup the key names (ie. there will only be one |
This filters duplicate dynamic templates when merging different component templates that specify the same dynamic template and when merging the mappings specified in the request with the ones in the index template.
|
@elasticmachine update branch |
dakrone
left a comment
There was a problem hiding this comment.
I left a couple of comments similar to what we talked about regarding naming, thanks for doing this Andrei!
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java
Outdated
Show resolved
Hide resolved
dakrone
left a comment
There was a problem hiding this comment.
LGTM, thanks for working on this Andrei!
Dynamic templates can contain multiple templates with the same name. This commit changes the way V2 index templates mappings are resolved to add deduplication of dynamic templates when resolving the mappings, by having the last dynamic templates override the ones defined with the same name earlier in the `dynamic_templates` array. This also filters duplicate dynamic templates when merging different component templates that specify the same dynamic template and when merging the mappings specified in the request with the ones in the index template. (cherry picked from commit eb4a557) Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
Dynamic templates can contain multiple templates with the same name. This commit changes the way V2 index templates mappings are resolved to add deduplication of dynamic templates when resolving the mappings, by having the last dynamic templates override the ones defined with the same name earlier in the `dynamic_templates` array. This also filters duplicate dynamic templates when merging different component templates that specify the same dynamic template and when merging the mappings specified in the request with the ones in the index template. (cherry picked from commit eb4a557) Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
Dynamic templates can contain multiple templates with the same name. This
commit changes the way V2 index templates mappings are resolved to add
deduplication of dynamic templates when resolving the mappings, by having
the last dynamic templates override the ones defined with the same name
earlier in the
dynamic_templatesarray.Relates to #53101
Relates to #53326
Relates to #28988