use of org.elasticsearch.action.search.ClearScrollRequest in project elasticsearch by elastic.
the class RestClearScrollActionTests method testParseClearScrollRequest.
public void testParseClearScrollRequest() throws Exception {
XContentParser content = createParser(XContentFactory.jsonBuilder().startObject().array("scroll_id", "value_1", "value_2").endObject());
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
RestClearScrollAction.buildFromContent(content, clearScrollRequest);
assertThat(clearScrollRequest.scrollIds(), contains("value_1", "value_2"));
}
use of org.elasticsearch.action.search.ClearScrollRequest in project elasticsearch by elastic.
the class RestClearScrollAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String scrollIds = request.param("scroll_id");
ClearScrollRequest clearRequest = new ClearScrollRequest();
clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds)));
request.withContentOrSourceParamParserOrNull((xContentParser -> {
if (xContentParser != null) {
clearRequest.setScrollIds(null);
try {
buildFromContent(xContentParser, clearRequest);
} catch (IOException e) {
throw new IllegalArgumentException("Failed to parse request body", e);
}
}
}));
return channel -> client.clearScroll(clearRequest, new RestStatusToXContentListener<>(channel));
}
use of org.elasticsearch.action.search.ClearScrollRequest in project elasticsearch by elastic.
the class ParentTaskAssigningClientTests method testSetsParentId.
public void testSetsParentId() {
TaskId[] parentTaskId = new TaskId[] { new TaskId(randomAsciiOfLength(3), randomLong()) };
// This mock will do nothing but verify that parentTaskId is set on all requests sent to it.
NoOpClient mock = new NoOpClient(getTestName()) {
@Override
protected <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute(Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) {
assertEquals(parentTaskId[0], request.getParentTask());
super.doExecute(action, request, listener);
}
};
try (ParentTaskAssigningClient client = new ParentTaskAssigningClient(mock, parentTaskId[0])) {
// All of these should have the parentTaskId set
client.bulk(new BulkRequest());
client.search(new SearchRequest());
client.clearScroll(new ClearScrollRequest());
// Now lets verify that unwrapped calls don't have the parentTaskId set
parentTaskId[0] = TaskId.EMPTY_TASK_ID;
client.unwrap().bulk(new BulkRequest());
client.unwrap().search(new SearchRequest());
client.unwrap().clearScroll(new ClearScrollRequest());
}
}
use of org.elasticsearch.action.search.ClearScrollRequest in project elasticsearch by elastic.
the class ClientScrollableHitSource method clearScroll.
@Override
public void clearScroll(String scrollId, Runnable onCompletion) {
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.addScrollId(scrollId);
/*
* Unwrap the client so we don't set our task as the parent. If we *did* set our ID then the clear scroll would be cancelled as
* if this task is cancelled. But we want to clear the scroll regardless of whether or not the main request was cancelled.
*/
client.unwrap().clearScroll(clearScrollRequest, new ActionListener<ClearScrollResponse>() {
@Override
public void onResponse(ClearScrollResponse response) {
logger.debug("Freed [{}] contexts", response.getNumFreed());
onCompletion.run();
}
@Override
public void onFailure(Exception e) {
logger.warn((Supplier<?>) () -> new ParameterizedMessage("Failed to clear scroll [{}]", scrollId), e);
onCompletion.run();
}
});
}
use of org.elasticsearch.action.search.ClearScrollRequest in project elasticsearch by elastic.
the class RestClearScrollActionTests method testParseClearScrollRequestWithUnknownParamThrowsException.
public void testParseClearScrollRequestWithUnknownParamThrowsException() throws Exception {
XContentParser invalidContent = createParser(XContentFactory.jsonBuilder().startObject().array("scroll_id", "value_1", "value_2").field("unknown", "keyword").endObject());
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
Exception e = expectThrows(IllegalArgumentException.class, () -> RestClearScrollAction.buildFromContent(invalidContent, clearScrollRequest));
assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]"));
}
Aggregations