From 7f08ab301d050c91796c7be41d39cad8712c4d71 Mon Sep 17 00:00:00 2001 From: Jun Ohtani Date: Wed, 22 Apr 2015 23:55:15 +0900 Subject: [PATCH] Fix RestSearchScrollAction to also accept source parameter instead of the request body --- .../action/search/RestSearchScrollAction.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java b/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java index cd2dbf856a3..df363aadd74 100644 --- a/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java +++ b/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java @@ -23,6 +23,7 @@ import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchScrollRequest; import org.elasticsearch.client.Client; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -68,16 +69,16 @@ public class RestSearchScrollAction extends BaseRestHandler { searchScrollRequest.scroll(new Scroll(parseTimeValue(scroll, null))); } - if (request.hasContent()) { - XContentType type = XContentFactory.xContentType(request.content()); + if (request.hasContent() || request.hasParam("source")) { + XContentType type = contentType(request); if (type == null) { if (scrollId == null) { - scrollId = RestActions.getRestContent(request).toUtf8(); + scrollId = bodyContent(request).toUtf8(); searchScrollRequest.scrollId(scrollId); } } else { // NOTE: if rest request with xcontent body has request parameters, these parameters override xcontent values - buildFromContent(request.content(), searchScrollRequest); + buildFromContent(bodyContent(request), searchScrollRequest); } } client.searchScroll(searchScrollRequest, new RestStatusToXContentListener(channel)); @@ -107,4 +108,23 @@ public class RestSearchScrollAction extends BaseRestHandler { } } + private XContentType contentType(final RestRequest request) { + if (request.hasContent()) { + return XContentFactory.xContentType(request.content()); + } else if (request.hasParam("source")) { + return XContentFactory.xContentType(request.param("source")); + } + throw new ElasticsearchIllegalArgumentException("Can't guess contentType neither source nor content available"); + } + + private BytesReference bodyContent(final RestRequest request) { + if (request.hasContent()) { + return request.content(); + } else if (request.hasParam("source")) { + return new BytesArray(request.param("source")); + } + throw new ElasticsearchIllegalArgumentException("Can't guess contentType neither source nor content available"); + } + + }