Search in sources :

Example 1 with ClearScrollRequest

use of org.graylog.shaded.elasticsearch7.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 2 with ClearScrollRequest

use of org.graylog.shaded.elasticsearch7.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 3 with ClearScrollRequest

use of org.graylog.shaded.elasticsearch7.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 4 with ClearScrollRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.ClearScrollRequest in project presto by prestodb.

the class ElasticsearchClient method clearScroll.

public void clearScroll(String scrollId) {
    ClearScrollRequest request = new ClearScrollRequest();
    request.addScrollId(scrollId);
    try {
        client.clearScroll(request);
    } catch (IOException e) {
        throw new PrestoException(ELASTICSEARCH_CONNECTION_ERROR, e);
    }
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) IOException(java.io.IOException)

Example 5 with ClearScrollRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.ClearScrollRequest in project graylog2-server by Graylog2.

the class ScrollResultES7 method cancel.

@Override
public void cancel() throws IOException {
    final ClearScrollRequest request = new ClearScrollRequest();
    request.addScrollId(scrollId);
    client.executeWithIOException((c, requestOptions) -> c.clearScroll(request, requestOptions), "Unable to cancel scrolling search request");
}
Also used : ClearScrollRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.ClearScrollRequest)

Aggregations

ClearScrollRequest (org.elasticsearch.action.search.ClearScrollRequest)10 SearchRequest (org.elasticsearch.action.search.SearchRequest)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 SearchScrollRequest (org.elasticsearch.action.search.SearchScrollRequest)2 XContentParser (org.elasticsearch.common.xcontent.XContentParser)2 SearchHit (org.elasticsearch.search.SearchHit)2 PrestoException (com.facebook.presto.spi.PrestoException)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)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 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)1