Search in sources :

Example 1 with ClearScrollRequest

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"));
}
Also used : ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 2 with ClearScrollRequest

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));
}
Also used : XContentParser(org.elasticsearch.common.xcontent.XContentParser) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Arrays(java.util.Arrays) Settings(org.elasticsearch.common.settings.Settings) DELETE(org.elasticsearch.rest.RestRequest.Method.DELETE) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) RestStatusToXContentListener(org.elasticsearch.rest.action.RestStatusToXContentListener) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) IOException(java.io.IOException)

Example 3 with ClearScrollRequest

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());
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Action(org.elasticsearch.action.Action) TaskId(org.elasticsearch.tasks.TaskId) ActionRequest(org.elasticsearch.action.ActionRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ActionResponse(org.elasticsearch.action.ActionResponse) ActionRequestBuilder(org.elasticsearch.action.ActionRequestBuilder) ActionListener(org.elasticsearch.action.ActionListener) ActionRequest(org.elasticsearch.action.ActionRequest) NoOpClient(org.elasticsearch.test.client.NoOpClient) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest)

Example 4 with 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();
        }
    });
}
Also used : Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) ClearScrollResponse(org.elasticsearch.action.search.ClearScrollResponse) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Example 5 with ClearScrollRequest

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]"));
}
Also used : ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

ClearScrollRequest (org.elasticsearch.action.search.ClearScrollRequest)5 XContentParser (org.elasticsearch.common.xcontent.XContentParser)3 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 Supplier (org.apache.logging.log4j.util.Supplier)1 Action (org.elasticsearch.action.Action)1 ActionListener (org.elasticsearch.action.ActionListener)1 ActionRequest (org.elasticsearch.action.ActionRequest)1 ActionRequestBuilder (org.elasticsearch.action.ActionRequestBuilder)1 ActionResponse (org.elasticsearch.action.ActionResponse)1 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)1 ClearScrollResponse (org.elasticsearch.action.search.ClearScrollResponse)1 SearchRequest (org.elasticsearch.action.search.SearchRequest)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 Settings (org.elasticsearch.common.settings.Settings)1 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 RestController (org.elasticsearch.rest.RestController)1