-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Validate that fields are defined only once. #15243
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
Conversation
Still to be defined: how to deal with pre-existing mappings that have the problem? Should we ignore the problem for old versions or should we try to "fix" the mapping? |
The change LGTM. For how to deal with existing broken mappings, I think we must fail? eg if a user has an object and field mapper with the same path, what would we do? "choose" one, effectively removing the other? The configuration is broken, the user should be alerted so they can fix their mappings (which will require a reindex). |
I don't know how to replicate the ExternalMapper case, but for meta-fields that are also defined as properties, I think it would be safe to drop the version inside properties when upgrading. In 1.7:
The Taking it one step further, if i define the
... the
... it screws up the parsing: |
Thanks @clintongormley. So from what I can tell, this won't be an issue when upgrading directly from 1.x as mapping updates that try to add metadata fields under the root are ignored. On the other hand 2.x allows to put such meta fields under the root object, and the upgrade would fail if we start rejecting it. However, DocumentParser rejects documents that have a metadata field at the root, so this can only happen with an explicit mapping update. So in the end I suspect that very few users would be impacted, so Ryan's proposal to fail at parsing time sounds more appealing to me than attempting to fix broken mappings (which is dangerous)? |
ae251e0
to
5faa7a8
Compare
I also pushed a new commit that tests that this validation also works for indices created on 2.x, which have their metadata mappers added to the root object. |
@jpountz sounds good to me. Rather make this solid than introduce complications to handle edge cases. |
There are two ways that a field can be defined twice: - by reusing the name of a meta mapper in the root object (`_id`, `_routing`, etc.) - by defining a sub-field both explicitly in the mapping and through the code in a field mapper (like ExternalMapper does) This commit adds new checks in order to make sure this never happens. Close elastic#15057
5faa7a8
to
5d5c659
Compare
Validate that fields are defined only once.
There are two ways that a field can be defined twice:
_id
,_routing
,etc.)
in a field mapper (like ExternalMapper does)
This commit adds new checks in order to make sure this never happens.
Close #15057