-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Restrict fields with the same name in different types to have the same core settings #11812
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
…ve the same core settings We currently are very lax about allowing data types to conflict for the same field name, across document types. This change makes the underlying map in MapperService a 1-1 map of field name to field type, and throws exception when new types are not compatible. To still allow changing a type, with parameters that are allowed to be changed, but for a field that exists in multiple types, a new parameter to index creation and put mapping API is added: update_all_types. This defaults to false, and the exception messages suggest using this parameter when trying to modify a setting that is allowed to be modified but is being limited by this restriction. There are also a couple changes which try to base fields from new types for dynamic mappings, and root mappers, on existing settings. For dynamic mappings this is important if the dynamic defaults have been changed. For root mappings, this is mostly just for backcompat when pre 2.0 root mappers could have their field type changed. fixes elastic#8871
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.
s/give/given/
The change looks great. I also played with the change, trying to add conflicting mappings at index creation time, through dynamic mappings and explicit mappings updates and things seem to work fine overall. I found some bugs wrt dynamic mappings that I fixed in your branch (hope you don't mind) and left comments for some other bugs. |
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.
When I did the following test:
DELETE test
PUT test
{
"mappings": {
"test1": {
"properties": {
"s": {
"type": "binary"
}
}
}
}
}
PUT test/test2/_mapping
{
"test2": {
"properties": {
"s": {
"type": "string"
}
}
}
}
I got the following response:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Mapper for [s] conflicts with existing mapping in other types[mapper [s] has different index values]"
}
],
"type": "illegal_argument_exception",
"reason": "Mapper for [s] conflicts with existing mapping in other types[mapper [s] has different index values]"
},
"status": 400
}
I was surprised to see an error about options while the mapped type isn't even the same. I suspect it comes from this method which starts validating options without first comparing the type implementation?
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 agree we need a better error message here. We can't just check the class like mappers do, since some mappers use MappedFieldType directly. I think I will add a setting to MappedFieldType which is the "typename"? This will give a much better error than what we get now IMO (the actual type, instead of a classname the user knows nothing about).
I left a bunch of comments - I'd like to talk the concurrency aspects through with you in person here and I also wonder if we can get rid of |
@s1monw @jpountz I pushed a new commit. The one outstanding thing is the better error message for conflicting data types. As for |
Actually, now I'm not sure about |
LGTM! |
awesome!!!! - please open a followup for the craziness around concurrent maps etc. LGTM |
Restrict fields with the same name in different types to have the same core settings
We currently are very lax about allowing data types to conflict for the
same field name, across document types. This change makes the underlying
map in MapperService a 1-1 map of field name to field type, and throws
exception when new types are not compatible.
To still allow changing a type, with parameters that are allowed to be
changed, but for a field that exists in multiple types, a new parameter
to index creation and put mapping API is added: update_all_types.
This defaults to false, and the exception messages suggest using
this parameter when trying to modify a setting that is allowed to be
modified but is being limited by this restriction.
There are also a couple changes which try to base fields from new types
for dynamic mappings, and root mappers, on existing settings. For
dynamic mappings this is important if the dynamic defaults have been
changed. For root mappings, this is mostly just for backcompat when
pre 2.0 root mappers could have their field type changed.
fixes #8871