diff options
Diffstat (limited to 'core/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java')
-rw-r--r-- | core/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java index e7ee7c7397..47252f5a10 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java @@ -20,12 +20,10 @@ package org.elasticsearch.rest.action.search; import org.elasticsearch.action.search.ClearScrollRequest; -import org.elasticsearch.action.search.ClearScrollResponse; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; @@ -50,26 +48,34 @@ public class RestClearScrollAction extends BaseRestHandler { String scrollIds = request.param("scroll_id"); ClearScrollRequest clearRequest = new ClearScrollRequest(); clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds))); - BytesReference body = request.contentOrSourceParam(); - if (body.length() > 0) { - if (XContentFactory.xContentType(body) == null) { - scrollIds = body.utf8ToString(); - clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds))); + request.withContentOrSourceParamParserOrNullLenient((xContentParser -> { + if (xContentParser == null) { + if (request.hasContent()) { + // TODO: why do we accept this plain text value? maybe we can just use the scroll params? + BytesReference body = request.content(); + String bodyScrollIds = body.utf8ToString(); + clearRequest.setScrollIds(Arrays.asList(splitScrollIds(bodyScrollIds))); + } } else { // NOTE: if rest request with xcontent body has request parameters, these parameters does not override xcontent value clearRequest.setScrollIds(null); - try (XContentParser parser = request.contentOrSourceParamParser()) { - buildFromContent(parser, clearRequest); + try { + buildFromContent(xContentParser, clearRequest); } catch (IOException e) { throw new IllegalArgumentException("Failed to parse request body", e); } } - } + })); - return channel -> client.clearScroll(clearRequest, new RestStatusToXContentListener<ClearScrollResponse>(channel)); + return channel -> client.clearScroll(clearRequest, new RestStatusToXContentListener<>(channel)); + } + + @Override + public boolean supportsPlainText() { + return true; } - public static String[] splitScrollIds(String scrollIds) { + private static String[] splitScrollIds(String scrollIds) { if (scrollIds == null) { return Strings.EMPTY_ARRAY; } |