cleanup request parsing in RestSearchAction

This commit is contained in:
Areek Zillur 2016-03-16 17:01:47 -04:00
parent 44b3dc95a0
commit 22e12ab7c3
2 changed files with 7 additions and 19 deletions

View File

@ -92,7 +92,7 @@ public class RestSearchAction extends BaseRestHandler {
@Override @Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws IOException { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws IOException {
SearchRequest searchRequest = new SearchRequest(); SearchRequest searchRequest = new SearchRequest();
RestSearchAction.parseSearchRequest(searchRequest, queryRegistry, request, parseFieldMatcher, aggParsers, suggesters, null); parseSearchRequest(searchRequest, queryRegistry, request, parseFieldMatcher, aggParsers, suggesters, null);
client.search(searchRequest, new RestStatusToXContentListener<>(channel)); client.search(searchRequest, new RestStatusToXContentListener<>(channel));
} }
@ -123,16 +123,15 @@ public class RestSearchAction extends BaseRestHandler {
} }
if (restContent != null) { if (restContent != null) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
if (isTemplateRequest) { try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { context.reset(parser);
context.reset(parser); context.parseFieldMatcher(parseFieldMatcher);
context.parseFieldMatcher(parseFieldMatcher); if (isTemplateRequest) {
Template template = TemplateQueryParser.parse(parser, context.parseFieldMatcher(), "params", "template"); Template template = TemplateQueryParser.parse(parser, context.parseFieldMatcher(), "params", "template");
searchRequest.template(template); searchRequest.template(template);
} else {
searchRequest.source().parseXContent(parser, context, aggParsers, suggesters);
} }
} else {
RestActions.parseRestSearchSource(searchRequest.source(), restContent, indicesQueriesRegistry, parseFieldMatcher,
aggParsers, suggesters);
} }
} }

View File

@ -115,17 +115,6 @@ public class RestActions {
return queryBuilder; return queryBuilder;
} }
public static void parseRestSearchSource(SearchSourceBuilder source, BytesReference sourceBytes,
IndicesQueriesRegistry queryRegistry, ParseFieldMatcher parseFieldMatcher,
AggregatorParsers aggParsers, Suggesters suggesters)
throws IOException {
XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes);
QueryParseContext queryParseContext = new QueryParseContext(queryRegistry);
queryParseContext.reset(parser);
queryParseContext.parseFieldMatcher(parseFieldMatcher);
source.parseXContent(parser, queryParseContext, aggParsers, suggesters);
}
/** /**
* Get Rest content from either payload or source parameter * Get Rest content from either payload or source parameter
* @param request Rest request * @param request Rest request