-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Stop automatically nesting mappings in index creation requests. #36924
Conversation
Pinging @elastic/es-core-features |
1f536ff
to
1161e5f
Compare
Pinging @elastic/es-search |
1161e5f
to
7ff9d51
Compare
Now that we unwrap mappings in DocumentMapperParser#extractMappings, it is not necessary for the mapping definition to always be nested under the type. This leniency around the mapping format was added in 2341825.
…er test coverage.
7ff9d51
to
2b395aa
Compare
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.
Nice.
Looks like there's some test failures stemming from mixed version clusters. The stack trace suggests it's the 6.7 node attempting some internal merging of mapping definitions from 7.0 and triggers the (removed in 7.0) exception complaining about the lack of root object:
|
Thanks @jpountz for the review, and @markharwood for digging into the build failure. I've decided to pull out the 'Make sure empty mappings are accepted' part of this PR into #37089. I can then backport that PR, which should fix the BWC failures we're now seeing around empty mappings. |
bfb70b8
to
6c258ca
Compare
@elasticmachine run gradle build tests 1 |
…tic#36924) Now that we unwrap mappings in DocumentMapperParser#extractMappings, it is not necessary for the mapping definition to always be nested under the type. This leniency around the mapping format was added in 2341825.
I'm going to revert this PR because of the issue uncovered in #37208, and I think we need to reconsider the overall approach. In short, the problem is that index templates store the mapping value as a string, with the mapping definition is nested under the type name. When trying to create an index with unnested mappings, we attempt to merge that map with the nested mappings from the index template, which produces an incorrect result. I now think that instead of standardizing on unnested mappings in indices.create + indices.put_template, for 7.0 we should actually standardize on having all mappings be nested, as @markharwood suggested in #35866. My reasoning is that stored index templates nest the mappings under the type name, so it is more robust and simpler to reason about if we stick to this format across all server requests + code related to index creation. |
The call
CreateIndexRequest#mapping(String type, Map<String, ?> source)
currently checks if root of the mapsource
is the type name, and if not, makes sure it is nested under the type. It looks like we have this logic because at one point, we tried to maintain the invariant that all mapping values in the request were nested under the type name.However, since 2341825, this is no longer necessary, and in fact almost none of the other
CreateIndexRequest#mapping
methods perform this automatic detection + nesting. This PR is a step towards standardizingCreateIndexRequest
so that mapping values are not expected to be nested under the type name.Automatically nesting the mapping values has a few downsides:
It makes it difficult to introduce fully typeless mapping methods onto this class, as we move towards our goal of removing types. This is because when a typeless mapping definition is provided, it may be automatically converted to one that contains the type. In particular, this logic is making it very hard to deprecate types in the HLRC for 'create index' and 'put index template' requests.
It is redundant, since the type name is already stored as the key in the
mappings
map.When using the above
mapping
method then serializing the request to xContent, the mappings will be doubly nested under the type name, as in this example:Because of our leniency around mappings, these doubly-nested mappings are still able to be re-parsed. However, this situation is buggy and potentially fragile.
Note that
PutIndexTemplateRequest
has the same issue, and would have to be changed in an analogous way.