-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Better validation of mapping JSON #7534
Conversation
// Because this mapper extends LongFieldMapper the null_value field will be added to the JSON when transferring cluster state | ||
// between nodes so we have to remove the entry here so that the validation doesn't fail | ||
// TODO should murmur3 support null_value? at the moment if a user sets null_value it has to be silently ignored since we can't | ||
// determine whether the JSON is the original JSON from the user or if its the serialised cluster state being passed between nodes. |
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 would like to get people's thoughts on this in particular as I am not sure which way to go on it
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.
null_value
is undocumented for murmur3
and also it seemed to have never worked at all (was not parsed and the set value ~0L was never used). I think we should remove it. Replacing the ~0L in ctor with null?
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.
Arbitrary null values don't really make sense for this mapper so I think it makes sense to remove support for it.
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.
However I think it is important that the default configuration emits an empty json
Was the intention of this to also work for root mappers like |
For the context suggester, one can still put arbitrary fields into the context, for example:
|
This does not seem to work work for multi_fields yet, example below. This should throw an exception but does not:
|
docBuilder.put(typeParser.parse(fieldName, fieldNodeMap, parserContext)); | ||
fieldNodeMap.remove("type"); | ||
if (!fieldNodeMap.isEmpty()) { | ||
throw new MapperParsingException("Field mapping for [" + fieldName + "] not empty after parsing! Remaining fields: " + getRemainingFields(fieldNodeMap)); |
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.
Does this message go back to the end user? If so the fact that a map must be empty is more of an implementation detail than an meaningful error message for the end user. Something like "Mapping definition for field X has unsupported parameters: foo, bar" would be more appropriate.
@colings86 I left some comments but I love this change already so much! One thing I noticed is that if I add a faulty dynamic_mapping, the parser will still not complain:
Should we do something about that as well? |
@brwe I have implemented most of your comments and left some replies on some others. I agree that the dynamic mapping should also be fixed but maybe we should open a new issue for this so that this one can be merged first? |
@colings86 please could you confirm whether this PR would fix #8317? |
@clintongormley yes this PR will fix #8317 |
Suggestion from @brwe and @jpountz: Make it so the strict validation is only turned on if the index version is on or after the version that releases this change. This will eliminate the possibility of having a mapping that was created in a previous version that cannot be read by the current version. This is a precaution rather than a necessity |
if (indexVersionCreated.onOrAfter(Version.V_2_0_0)) { | ||
throw new MapperParsingException(message + getRemainingFields(fieldNodeMap)); | ||
} else { | ||
logger.debug(message + "{}", getRemainingFields(fieldNodeMap)); |
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.
or just message + getRemainingFields(fieldNodeMap)
?
@clintongormley @colings86 As far as I am concerned, I think it's ready, I just left minor notes. There is an issue with fielddata and norms settings, but this PR solves most of the issue so I think we should not try to solve it in this PR and merge soon. |
agree with @jpountz |
The parsers for the mappers now remove each setting as they parse it and an error will be thrown if any settings are left after parsing is complete
Closes #7205