-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
toString for SearchRequestBuilder and CountRequestBuilder #9944
toString for SearchRequestBuilder and CountRequestBuilder #9944
Conversation
I think the |
I see what you mean @kimchy . I think that there are a couple of different problems with this First of all it prints out only part of the request (index, type, routing etc. are ignored) which in my mind relates to the request body (when the request comes in through REST layer). This hasn't changed in this PR, but it did get more convoluted since I am now attempting to print out what is actually going to be executed (hence merging extra_source and source, cause that is what happen at execution time anyway). Also, I wonder if users expect the output to be a valid json query that can be sent back to elasticsearch or not. If we add the That said, what I am proposing is a bigger (breaking?) change that deserves its own issue and discussion, and should be applied to every request consistently (after #9201). I am leaning towards fixing the actual bug only in this PR, the fact that the |
@javanna yea, I think fixing the actual bug here is the best way forward. Personally, I am leaning towards not adding the behavior of being able to take a request If we want to take such a project of having the request be represented as rest requests, then we need to have something like |
I just opened #9962 to keep track of the bigger change we've been discussing. As for fixing this bug, what should we do?
|
if I understand correctly @kimchy , you vote for
Is that right? |
I think we need to fix the bug first of all..., we can improve toString while we are at it, but maybe in a different pull request? |
e0a763b
to
6067cda
Compare
Agreed @kimchy I updated the PR to only fix the bug. Removed the extra_source merge. Note that extra_source is ignored, as before the fix. But the right source gets now printed out depending on what's set. Let me know what you think |
return sourceBuilder.toString(); | ||
} | ||
if (request.source() != null) { | ||
return request.source().toUtf8(); |
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.
the source might be SMILE or CBOR, and then we can't convert it to utf8?
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 boy I totally missed this, fixing
@javanna left a minor comment |
1ab93db
to
7f8dad8
Compare
… without wiping the request source Broaden SearchRequestBuilder#toString to support the different ways a query can be set to it. Also printed out a merged version of source and extraSrouce in case there in case any extraSource is set, to reflect what will happen when executing the request builder. Closes elastic#5576
Similarly to what SearchRequestBuilder does, we print out a string representation of they query that is going to be executed when executing the request builder. Closes elastic#5555
7f8dad8
to
e0f9ec6
Compare
Updated to properly handle binary formats as well and added tests for it, can you have another look please @kimchy ? |
Hey @javanna , how is the bug fixing going? I saw 1.5.0 has been released. Does it include the fix of this toString() bug? I noticed you guys talking about the use of toString(). IMHO, I feel the proper use case of toString() would be only for logging and debugging. In this case, developers probably wouldn't care too much about whether toString() returns a proper JSON string or something else, as long as it returns correct and enough information about the QueryBuilder object. The most important thing is to make sure that calling toString() will never change the state of QueryBuilder, which is probably something you guys could start with to fix the bug, and then collect feedback, and keep improving it. Thanks! |
Hi @cooniur the PR is still open which means that it didn't make it into |
ping @kimchy can you have a look please? |
@jpountz maybe you can have a look? |
LGTM |
Merged to master, 1.x and 1.5. |
return "{ \"error\" : \"" + ExceptionsHelper.detailedMessage(e) + "\"}"; | ||
} | ||
} | ||
return new QuerySourceBuilder().toString(); |
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.
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 it is expected
Hey @javanna , thanks for fixing this issue in 1.6! Being waiting for it for a long time but eventually get it! |
Fixed SearchRequestBuilder#toString to not wipe the request source when called.
Improved SearchRequestBuilder#toString to support the different ways a query can be set to it. Also printed out a merged version of source and extraSrouce in case there in case any extraSource is set, to reflect what will happen when executing the request builder.
Implemented toString in CountRequestBuilder
Closes #5576
Closes #5555