Skip to content
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

Closed

Conversation

johtani
Copy link
Contributor

@johtani johtani commented Dec 27, 2014

Add json support to scroll, clear scroll, and analyze
And change documents

Closes #5866

@@ -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) {
Copy link
Member

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).

Copy link
Contributor Author

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?

@martijnvg
Copy link
Member

@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.

@johtani
Copy link
Contributor Author

johtani commented Jan 14, 2015

@martijnvg I pushed some changes.

  • The parsing move to transport action layer
  • Add AnalyzeSourceBuilder and SearchScrollSourceBuilder

I have a question about SearchScrollRequest.
It is difficult to remove scrollId and scroll because SearchScrollRequest is used in TransportSearchScrollQueryAndFetchAction and TransportSearchScrollQueryThenFetchAction.
Now, I re-use SearchScrollRequest in TransportSearchScrollAction.
Do you have any idea?

@@ -78,6 +84,34 @@ protected void doExecute(SearchScrollRequest request, ActionListener<SearchRespo
}
}

private void parseSource(SearchScrollRequest request) {
if (request.source() != null) {
Copy link
Member

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.

Copy link
Contributor Author

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?

@martijnvg
Copy link
Member

@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.

@s1monw
Copy link
Contributor

s1monw commented Mar 16, 2015

@martijnvg are you picking this up?

@johtani johtani force-pushed the fix/support_json_scroll_and_analyze_api branch from 4de5abb to 6787a5e Compare March 18, 2015 15:36
@johtani
Copy link
Contributor Author

johtani commented Mar 18, 2015

@martijnvg Rebased a branch. Please review it.


/**
*/
public class ClearScrollRequest extends ActionRequest<ClearScrollRequest> {

private List<String> scrollIds;
private BytesReference source;
private boolean unsafe;
Copy link
Member

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.

@martijnvg
Copy link
Member

@johtani looks good. I left a couple of comments. Can you also squash the existing commits into a single commit?

@johtani johtani force-pushed the fix/support_json_scroll_and_analyze_api branch from 6787a5e to 5cdc347 Compare March 20, 2015 07:36
@johtani
Copy link
Contributor Author

johtani commented Mar 20, 2015

@martijnvg Thanks. Add comment and remove unsafe property. And squash into a single commit.


private String field;
private BytesReference source;
private boolean unsafe;
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member

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)

@martijnvg
Copy link
Member

@johtani LGTM. I think the point @rjernst raised about unsafe in general should be discussed in a different issue.

@johtani
Copy link
Contributor Author

johtani commented Mar 23, 2015

merged 16083d4

@johtani johtani closed this Mar 23, 2015
@bleskes
Copy link
Contributor

bleskes commented Mar 23, 2015

awesome @johtani

@bleskes
Copy link
Contributor

bleskes commented Mar 23, 2015

@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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space

@bleskes
Copy link
Contributor

bleskes commented Apr 20, 2015

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
@johtani
Copy link
Contributor Author

johtani commented Apr 21, 2015

Thanks for your comments, @bleskes
I change analyzer.asciidoc and scroll.asciidoc, please check my English...
And fix the message of exception and remove AnalyzeRequest constructor with two parameters.

@@ -131,3 +130,63 @@
clear_scroll:
scroll_id: $scroll_id

---
"Basic scroll orverride param by JSON":
Copy link
Contributor

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"?

@bleskes
Copy link
Contributor

bleskes commented Apr 21, 2015

Left some documentation comments. Other than that, LGTM

@johtani
Copy link
Contributor Author

johtani commented Apr 21, 2015

Pushed. Fix documentations

@bleskes
Copy link
Contributor

bleskes commented Apr 22, 2015

LGTM. Thx

@johtani
Copy link
Contributor Author

johtani commented Apr 22, 2015

@bleskes Thanks. Should I get LGTM one more?

@bleskes
Copy link
Contributor

bleskes commented Apr 22, 2015

I think it's not needed. Up to you.

On Wed, Apr 22, 2015 at 10:24 AM, Jun Ohtani notifications@github.com
wrote:

@bleskes Thanks. Should I get LGTM one more?

Reply to this email directly or view it on GitHub:
#9076 (comment)

@johtani
Copy link
Contributor Author

johtani commented Apr 22, 2015

merged!

@johtani johtani closed this Apr 22, 2015
@kevinkluge kevinkluge removed the review label Apr 22, 2015
@clintongormley clintongormley changed the title Rest: Add json in request body to scroll, clear scroll, and analyze API Support JSON request body in scroll, clear scroll, and analyze APIs Jun 7, 2015
@johtani johtani deleted the fix/support_json_scroll_and_analyze_api branch April 25, 2016 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The scroll, clear scroll and analyze apis should support json in request body
6 participants