Skip to content
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 duplicate dynamic_templates names #51817

Closed
wants to merge 2 commits into from

Conversation

cbuescher
Copy link
Member

Currently the same dynamic_templates name can be used more than once in the
same mappings file. This most certainly is unintentional and can create issues like
those reported in #28988. Furthermore, when templates are matched later in
RootObjectMapper#findTemplate, it looks like we simply pick the first matching
one we see in the input array, so using the same template name twice sounds like
an error prone idea anyway. This change checks for duplicate names on parsing
and throws an error if we encounter the same name twice.

Closes #28988

Currently the same `dynamic_templates` name can be used more than once in the
same mappings file. This most certainly is unintentional and can create issues like
those reported in elastic#28988. Furthermore, when templates are matched later in
`RootObjectMapper#findTemplate`, it looks like we simply pick the first matching
one we see in the input array, so using the same template name twice sounds like
an error prone idea anyway. This change checks for duplicate names on parsing
and throws an error if we encounter the same name twice.

Closes elastic#28988
@cbuescher cbuescher added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types v8.0.0 v7.7.0 labels Feb 3, 2020
@cbuescher cbuescher requested a review from jtibshirani February 3, 2020 14:59
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Mapping)

@cbuescher
Copy link
Member Author

@jtibshirani I found this by accident since I was reviewing a PR in the same area earlier and thought this might be a simple fix. Let me know if this makes sense to you or if my thinking around the issue was a bit too shortsighted.

@@ -607,7 +607,7 @@ public void testDateDetectionInheritsFormat() throws Exception {
.endObject()
.endObject()
.startObject()
.startObject("dates")
.startObject("dates_with_explicit_format")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After having to change this test I'm not entirely sure anymore about the approach, in particular whether this test was lazily "missusing" a leniency in our code by using the name twice or wether this should work. In the end both templates seem to match different fields, so I'm not sure why the test used the same name?

Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbuescher since commenting on #28988, I now think that some users are relying on this behavior (where dynamic templates are not disallowed/ deduplicated). For example, we recently found out in #29200 (comment) that APM creates multiple dynamic with the same name, but with different match_mapping_type values.

Would it make sense to discuss as a team to make sure we're okay with the direction? A note that if we do go this direction, I think we'd need a deprecation period before we start throwing an error, as there are users taking advantage of the leniency.

@cbuescher
Copy link
Member Author

Would it make sense to discuss as a team to make sure we're okay with the direction

Absolutely, I wasn't aware of the other issue (#29200). From a first glance, it seems using the same dynamic template name there is problematic for similar reasons, but it makes sense to look at this from another angle again. We can close this PR for now and I will mark the original issue for discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types v7.7.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic templates should be deduplicated
4 participants