-
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
Prevent accidental field type property overwrites #51436
Conversation
When putting mapping definitions there currently appears to be loopholes by which e.g. the mapping parameters of a in inner field "f1" inside an object "obj" can be overwritten in the same mapping definition by specifying a field "obj.f1". FieldMapper.doMerge() currently only checks content type compatibility but e.g. overwrites its own fieldType with the one merged in. This can lead to suprising behaviour where users think the "merged" field properties (see e.g. ones merged in. This PR suggests trying to detect at least these kinds of incompatibilities and preventing merges like this to happen by leveraging the existing `checkCompatibility` mechanism on the fieldtype. Relates to elastic#51286
Pinging @elastic/es-search (:Search/Mapping) |
@jtibshirani asking for your initial opinion here mostly, do you think we should prevent scenarios like in #51436 (simplified in the test) to happen? Not sure if this is the best location to reject these kind of merge conflicts, you might be able to pinpoint better locations or strategies. |
Hello @cbuescher, I’ll first describe my understanding of what’s happening to check we’re on the same page:
If instead the definition is spread out over two ‘put mapping’ calls (add the field mapping, then later update it with a conflicting mapping), then we correctly catch the conflict. This is because we end up validating the new definition against the old one through This PR addresses step 3, but to me the core of the bug is in step 2 -- we silently allow the same field to be defined twice in a single mapping definition. We have an open issue #37437 about this issue. It would be great to discuss what we think the best behavior is -- my intuition is that we should disallow it because it probably indicates an accidental user error. It’s also not clear which field should be considered first or second (as you mentioned in #51286). It’s also not so clean that we validate whether field mappings can be merged in two separate places: |
Thanks @jtibshirani, your summary capture my findings around digging into #51286. I wasn't aware of the open issue around "Disallow defining the same field", maybe thats a better approach indeed. I opened this PR mostly to illustrate the problem and offer some solution to the validation step you mentioned in step 3, happy to wait out the discussion on the other issue. Should we keep this open for the time being or close and reopen if needed? |
Sounds good to me. |
When putting mapping definitions there currently appears to be loopholes by
which e.g. the mapping parameters of a in inner field "f1" inside an object "obj"
can be overwritten in the same mapping definition by specifying a field
"obj.f1". FieldMapper.doMerge() currently only checks content type compatibility
but e.g. overwrites its own fieldType with the one merged in. This can lead to
suprising behaviour where users think the "merged" field properties (see e.g.
ones merged in.
This PR suggests trying to detect at least these kinds of incompatibilities and
preventing merges like this to happen by leveraging the existing
checkCompatibility
mechanism on the fieldtype.Relates to #51286