-
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
keep _parent field while updating child type mapping #24407
Conversation
be able to update child type mapping without specifying _parent field instead of trying to update it to "null" as previously.
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
@colings86 please could somebody review this |
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.
Thanks @PnPie! This looks good. I left two comments regarding the test.
.startObject("_parent").field("type", "new_parent").endObject() | ||
.endObject().endObject().string(); | ||
DocumentMapper modParentMapper = parser.parse("child", new CompressedXContent(modParentMapping)); | ||
try { |
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.
Replace this try-catch block with an expectThrows(...)
call?
Exception e = expectThrows(IllegalArgumentException.class, () -> initMapper.merge(modParentMapper.mapping(), false))
assertThat(e.getMessage(), containsString("The _parent field's type option can't be changed:"));
.endObject().endObject().endObject().string(); | ||
DocumentMapper updatedMapper = parser.parse("child", new CompressedXContent(updatedMapping)); | ||
DocumentMapper mergedMapper = initMapper.merge(updatedMapper.mapping(), false); | ||
|
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.
Maybe also add a merge with current parent field and a new field?
String updatedMapping = XContentFactory.jsonBuilder().startObject().startObject("child")
.startObject("_parent").field("type", "parent").endObject()
.startObject("properties")
.startObject("field2").field("type", "text").endObject()
.endObject().endObject().endObject().string();
DocumentMapper updatedMapper = parser.parse("child", new CompressedXContent(updatedMapping));
DocumentMapper mergedMapper = initMapper.merge(updatedMapper.mapping(), false);
The parent field should not be updatable, but the it's fieldType is changed and the new one is applied. So this patch make it keep the original one while merging.
Thanks for your comments @martijnvg, I added a merge case with current parent field while I found a new problem: I cannot find the And then I found that the parent field name of a document is in format: So previously after this we can find the And I also add a test for trying to add parent field to an exiting mapper without parent. |
Cool, looks good @PnPie. I'll merge it in soon and backport to 5.x branch. |
A bug introduced in elastic#24407 currently prevents `eager_global_ordinals` from being updated. This new approach should fix the issue while still allowing mapping updates to not specify the `_parent` field if it doesn't need updating, which was the goal of elastic#24407.
Be able to update child type mapping without specifying it's
_parent
field, because it should be considered as unchanged if it is not explicitly specified.In this case, the merged mapper's
parentType
field should benull
, so we can just merge it to keep the original one instead of throwing an exception of "trying to change it to 'null' "Close #23381