-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add fromxcontent methods to index response #22229
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
Add fromxcontent methods to index response #22229
Conversation
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.
No need to review this file, it comes from #22196
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.
That's the only bit that changed since #22196
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.
ok, I think I had made you revert this change before, but maybe it's ok because we only print this section out in one place, so the _SHARDS name doesn't get copied to other places. One thing: what does this specific change improve? That ShardInfo outputs a valid object alone?
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'm also curious to understand where the rendering of the field was moved, I don't seem to find it in this PR. What is the outer object that is calling this toXContent Method?
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.
It has been moved to DocWriteResponse.innerToXContent() where
shardInfo.toXContent(builder, params);
has been changed to:
builder.field(_SHARDS, shardInfo);
so that ShardInfo is now a ToXContentObject.
This is important for the ObjectParser used to parse the IndexResponse which can then directly use ShardInfo.fromXContent(p).
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.
This change comes from #22196
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.
you also needed to upgrade the fact that you don't expect a field name to start with right? rather a start_object straightaway
javanna
left a comment
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.
left a few comments, no particular blockers though, looks good.
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.
this thing is so un-readable :) sorry I couldn't hold it. Loops and ifs read so much easier to me
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.
ok, I think I had made you revert this change before, but maybe it's ok because we only print this section out in one place, so the _SHARDS name doesn't get copied to other places. One thing: what does this specific change improve? That ShardInfo outputs a valid object alone?
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.
you also needed to upgrade the fact that you don't expect a field name to start with right? rather a start_object straightaway
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 think we can avoid repeating IndexResponse in all methods
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.
please do not use convertToMap, it uses content type auto-detection while we know the content-type upfront. just create a parser and call map against 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.
rather than using a map here, couldn't you call fromXContent again? would that make sense?
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.
can you clarify what this method parses?
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.
is it correct to do this in IndexResponse? I am a bit confused by who does what. Given the toXContent in IndexResponse that only prints out one field, I was expecting most of the parsing to be in DocWriteResponse. That may have to do again with me not understanding ObjectParser and how it works.
0d657e0 to
040ea0f
Compare
|
@javanna I updated this pull request with the latest changes in master. I'll be happy if you can have a look again. Few things to keep in mind:
|
javanna
left a comment
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.
left few minors, LGTM, @cbuescher want to have a look too? You will need shard failures in search too I think.
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.
it is quite odd that the only info we actually can parse back out of the ShardId is the index name. no index_uuid and no shard_id. Maybe we should look into carrying around the index name only as a follow-up in DocWriteResponse. I am not sure we need more, it doesn't seem like 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.
Right, that makes sense. I can change that in a follow up PR.
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.
We talked about this with Luca and we both think that we should not do this change. This would impact the serialization of DocWriteResponse in core in order to simplify things and carry less information from a client side point of view.
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 for changing 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.
should this randomization be enabled again?
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.
Yes, this is a leftover.
040ea0f to
64663db
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.
Also just to understand this: this change here only affects the toString() method, not the actual rest response?
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.
Yes
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.
Out of curiosity: why does this test the toString() method, the tests seems to indicate its about the xContent?
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.
Oh right - this is because Strings.toString() uses the toXContent method internally. I can replace this by a direct usage of toXContent.
|
@tlrx @javanna I also had a look, left a few understanding questions but other than that LGTM. Unfortunately the ReplicationResponse.Failure that is used there is slightly different from the ShardSearchFailure that is used in the SearchResponse. I will take a close look at it but at this point I think although they are quiet similar, we need to add parsing to both of them. |
|
@javanna @cbuescher Thanks! |
This commit adds the parsing fromXContent() methods to the IndexResponse class. The method is based on a ObjectParser because it is easier to use when parsing parent abstract classes like DocWriteResponse. It also changes the ReplicationResponse.ShardInfo so that it now implements ToXContentObject. This way, the ShardInfo.fromXContent() method can be used by the IndexResponse's ObjectParser.
64663db to
fdf0830
Compare
This commit adds the parsing fromXContent() methods to the IndexResponse class. The method is based on a ObjectParser because it is easier to use when parsing parent abstract classes like DocWriteResponse. It also changes the ReplicationResponse.ShardInfo so that it now implements ToXContentObject. This way, the ShardInfo.fromXContent() method can be used by the IndexResponse's ObjectParser.
This commit adds the parsing fromXContent() methods to the IndexResponse class. It's a pale copy of what has been done in elastic#22229.
This commit adds the parsing fromXContent() methods to the
IndexResponseclass. The method is based on aObjectParserbecause it is easier to reuse parsing method from parent abstract classes likeDocWriteResponse.It also changes a bit the toXContent() method of
ReplicationResponse.ShardInfoso that it now starts its own object. This way, theShardInfo.fromXContent()method can be directly referenced by the IndexResponse's ObjectParser.