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
Support JSON request body in scroll, clear scroll, and analyze APIs #9076
Support JSON request body in scroll, clear scroll, and analyze APIs #9076
Conversation
@@ -64,4 +73,58 @@ public void handleRequest(final RestRequest request, final RestChannel channel, | |||
analyzeRequest.charFilters(request.paramAsStringArray("char_filters", analyzeRequest.charFilters())); | |||
client.admin().indices().analyze(analyzeRequest, new RestToXContentListener<AnalyzeResponse>(channel)); | |||
} | |||
|
|||
public static void parseContent(AnalyzeRequest request, String text, BytesReference content) { |
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 the the parsing logic should be in TransportAnalyzeAction
instead? This way both rest and regular transport level requests deal with the same parameter parsing logic.
The AnalyzeRequest just holds a source
field , like search and percolate request. To make usage easier from transport client, there can be a AnalyzeSourceBuilder (similar to SearchSourceBuilder).
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.
@martijnvg Question about BWC.
Your comment means that we remove other fields from AnalyzeRequest and add a source field, right?
If we do that, I think we will break the backward compatibility.
Is it correct?
@johtani Thanks for opening this PR! I left a couple of comments regarding the fact that it seems better to do the parsing that is now in the rest layer in the transport action layer. |
@martijnvg I pushed some changes.
I have a question about SearchScrollRequest. |
@@ -78,6 +84,34 @@ protected void doExecute(SearchScrollRequest request, ActionListener<SearchRespo | |||
} | |||
} | |||
|
|||
private void parseSource(SearchScrollRequest request) { | |||
if (request.source() != null) { |
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 should have a helper method that does the scroll id parsing. Now clear scroll and scroll apis have dedicated parsing logic. Even though the parsing logic is slightly differently (array vs. single value), it would be nice to reuse the parsing logic. The parsing helper method should support parsing a single scroll id and multiple scroll ids.
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.
@martijnvg sorry, late reply. I push the change that I move parse methods to Helper class.
Does it make sense?
@johtani I see, yes removing that option would make things more complicated. I think we should then keep the scrollId and scroll fields on the SearchScrollRequest class. But then in TransportSearchScrollAction we should just parse the source and and set these option on the SearchScrollRequest class, so that the other subsequent actions should only use these options. These fields on the SearchScrollRequest should be internal/private for these other subsequent actions, even though these are public options. Any other usages should use the scroll source build instead. Regarding to the rest of the PR: the last change looks good and I left one comment. |
@martijnvg are you picking this up? |
4de5abb
to
6787a5e
Compare
@martijnvg Rebased a branch. Please review it. |
|
||
/** | ||
*/ | ||
public class ClearScrollRequest extends ActionRequest<ClearScrollRequest> { | ||
|
||
private List<String> scrollIds; | ||
private BytesReference source; | ||
private boolean unsafe; |
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 unsafe field can be removed from ClearScrollRequest, because in TransportClearScrollAction we don't fork the request. Everything happens on the calling thread.
@johtani looks good. I left a couple of comments. Can you also squash the existing commits into a single commit? |
6787a5e
to
5cdc347
Compare
@martijnvg Thanks. Add comment and remove unsafe property. And squash into a single commit. |
|
||
private String field; | ||
private BytesReference source; | ||
private boolean unsafe; |
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 this "unsafe" member really needed? Aside from having a very confusing name, can't we just check source == null
?
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.
Nevermind, I see why it is "unsafe" now. But do we really need to have all these crazy options on the request? Why can't we just always copy?
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. The reusing of the request body has always been there and it used in other apis too, maybe instead we should open a different issue and discuss if we should drop this? This would simplify the code and remove a potential pitfall (the unsafe support isn't a straightforward pattern)
merged 16083d4 |
awesome @johtani |
@johtani sorry, I had to back this one out because it failed many client tests . Not saying it's not good but we should consider adding a BWC layer. Will reach out to discuss this. I'm re-opening this PR to make sure it's not lost. |
analyzeRequest.field(parser.text()); | ||
} else if ("tokenizer".equals(currentFieldName) && token == XContentParser.Token.VALUE_STRING) { | ||
analyzeRequest.tokenizer(parser.text()); | ||
}else if (("token_filters".equals(currentFieldName) || "filters".equals(currentFieldName)) && token == XContentParser.Token.START_ARRAY) { |
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.
extra space
Thx @johtani , this looks great. I left some minor comments... |
Change analyze.asciidoc and scroll.asciidoc Remove a constructor with two param in AnalyzeRequest Fix exception messages Closes elastic#5866
Thanks for your comments, @bleskes |
@@ -131,3 +130,63 @@ | |||
clear_scroll: | |||
scroll_id: $scroll_id | |||
|
|||
--- | |||
"Basic scroll orverride param by JSON": |
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 call this "Body params override query string"?
Left some documentation comments. Other than that, LGTM |
Fix documentations Closes elastic#5866
Pushed. Fix documentations |
LGTM. Thx |
@bleskes Thanks. Should I get LGTM one more? |
I think it's not needed. Up to you. On Wed, Apr 22, 2015 at 10:24 AM, Jun Ohtani notifications@github.com
|
merged! |
Add json support to scroll, clear scroll, and analyze
And change documents
Closes #5866