Search in sources :

Example 1 with SearchScrollRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchScrollRequest in project elasticsearch by elastic.

the class RestSearchScrollAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String scrollId = request.param("scroll_id");
    SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
    searchScrollRequest.scrollId(scrollId);
    String scroll = request.param("scroll");
    if (scroll != null) {
        searchScrollRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
    }
    request.withContentOrSourceParamParserOrNull(xContentParser -> {
        if (xContentParser != null) {
            try {
                buildFromContent(xContentParser, searchScrollRequest);
            } catch (IOException e) {
                throw new IllegalArgumentException("Failed to parse request body", e);
            }
        }
    });
    return channel -> client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestStatusToXContentListener(org.elasticsearch.rest.action.RestStatusToXContentListener) Scroll(org.elasticsearch.search.Scroll) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) XContentParser(org.elasticsearch.common.xcontent.XContentParser) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) TimeValue(org.elasticsearch.common.unit.TimeValue) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) TimeValue.parseTimeValue(org.elasticsearch.common.unit.TimeValue.parseTimeValue) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) Scroll(org.elasticsearch.search.Scroll) IOException(java.io.IOException) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest)

Example 2 with SearchScrollRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchScrollRequest in project elasticsearch by elastic.

the class RestSearchScrollActionTests method testParseSearchScrollRequest.

public void testParseSearchScrollRequest() throws Exception {
    XContentParser content = createParser(XContentFactory.jsonBuilder().startObject().field("scroll_id", "SCROLL_ID").field("scroll", "1m").endObject());
    SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
    RestSearchScrollAction.buildFromContent(content, searchScrollRequest);
    assertThat(searchScrollRequest.scrollId(), equalTo("SCROLL_ID"));
    assertThat(searchScrollRequest.scroll().keepAlive(), equalTo(TimeValue.parseTimeValue("1m", null, "scroll")));
}
Also used : XContentParser(org.elasticsearch.common.xcontent.XContentParser) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest)

Example 3 with SearchScrollRequest

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

the class ScrollResultES7 method nextSearchResult.

private SearchResponse nextSearchResult() throws IOException {
    final SearchScrollRequest scrollRequest = new SearchScrollRequest(this.scrollId);
    scrollRequest.scroll(TimeValue.parseTimeValue(this.scroll, DEFAULT_SCROLL, "scroll time"));
    return client.executeWithIOException((c, requestOptions) -> c.scroll(scrollRequest, requestOptions), "Unable to retrieve next chunk from search: ");
}
Also used : SearchScrollRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchScrollRequest)

Example 4 with SearchScrollRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchScrollRequest in project elasticsearch by elastic.

the class ClientScrollableHitSource method doStartNextScroll.

@Override
protected void doStartNextScroll(String scrollId, TimeValue extraKeepAlive, Consumer<? super Response> onResponse) {
    searchWithRetry(listener -> {
        SearchScrollRequest request = new SearchScrollRequest();
        request.scrollId(scrollId).scroll(timeValueNanos(firstSearchRequest.scroll().keepAlive().nanos() + extraKeepAlive.nanos()));
        client.searchScroll(request, listener);
    }, r -> consume(r, onResponse));
}
Also used : SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest)

Example 5 with SearchScrollRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchScrollRequest in project elasticsearch by elastic.

the class RestSearchScrollActionTests method testParseSearchScrollRequestWithUnknownParamThrowsException.

public void testParseSearchScrollRequestWithUnknownParamThrowsException() throws Exception {
    SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
    XContentParser invalidContent = createParser(XContentFactory.jsonBuilder().startObject().field("scroll_id", "value_2").field("unknown", "keyword").endObject());
    Exception e = expectThrows(IllegalArgumentException.class, () -> RestSearchScrollAction.buildFromContent(invalidContent, searchScrollRequest));
    assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]"));
}
Also used : SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

SearchScrollRequest (org.elasticsearch.action.search.SearchScrollRequest)5 XContentParser (org.elasticsearch.common.xcontent.XContentParser)3 TestSupport (com.hazelcast.jet.core.test.TestSupport)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 IOException (java.io.IOException)1 TotalHits (org.apache.lucene.search.TotalHits)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 BytesArray (org.elasticsearch.common.bytes.BytesArray)1 Settings (org.elasticsearch.common.settings.Settings)1 Text (org.elasticsearch.common.text.Text)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1 TimeValue.parseTimeValue (org.elasticsearch.common.unit.TimeValue.parseTimeValue)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 GET (org.elasticsearch.rest.RestRequest.Method.GET)1 POST (org.elasticsearch.rest.RestRequest.Method.POST)1 RestStatusToXContentListener (org.elasticsearch.rest.action.RestStatusToXContentListener)1