Check mapping compatibility up-front. #15123
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have a bug when updating an existing mapping and the mapping update conflicts
with another type. In such a case, the mapping is already partially applied
before we raise the exception, which can lead to all sorts of bugs.
This commit moves the compatibility checks up-front so that we don't start
applying a mapping before we are sure that it is not only applicable to the
current type but also to other types.
Note that this might break compatibility for some users: we had some tests
that checked that fields that did not have a conflict were added even though
other fields from the same mapping update were not compatible. This does not
work anymore.
MapperService.merge has been refactored to take a map of mapping updates so
that we can perform some cross-type validation (necessary for _parent) that
was previously spread in-between MapperService and MetaDataMappingService.
We now also verify that fields are defined only once in a given mapping. It
was previously possible to have a field twice either by reusing the name of
a metadata mapper or by using subfields both explicitly in a plugin and in
the code of a field mapper.
The check that _parent can't point to an existing type would only be actually
applied if the master node has mappings locally. So for instance in case of
dedicated master nodes, it would be ignored. This is fixed now by adding
mappings from all types when an index does not exist locally, instead of only
mappings from the types that are being updated.