Search in sources :

Example 11 with RestStatusToXContentListener

use of org.opensearch.rest.action.RestStatusToXContentListener in project OpenSearch by opensearch-project.

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) {
            // NOTE: if rest request with xcontent body has request parameters, values parsed from request body have the precedence
            try {
                searchScrollRequest.fromXContent(xContentParser);
            } catch (IOException e) {
                throw new IllegalArgumentException("Failed to parse request body", e);
            }
        }
    });
    return channel -> client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<>(channel));
}
Also used : POST(org.opensearch.rest.RestRequest.Method.POST) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) TimeValue.parseTimeValue(org.opensearch.common.unit.TimeValue.parseTimeValue) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) Set(java.util.Set) IOException(java.io.IOException) List(java.util.List) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) RestStatusToXContentListener(org.opensearch.rest.action.RestStatusToXContentListener) Arrays.asList(java.util.Arrays.asList) BaseRestHandler(org.opensearch.rest.BaseRestHandler) Scroll(org.opensearch.search.Scroll) Collections(java.util.Collections) Scroll(org.opensearch.search.Scroll) IOException(java.io.IOException) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest)

Aggregations

IOException (java.io.IOException)11 List (java.util.List)11 NodeClient (org.opensearch.client.node.NodeClient)11 BaseRestHandler (org.opensearch.rest.BaseRestHandler)11 RestRequest (org.opensearch.rest.RestRequest)11 RestStatusToXContentListener (org.opensearch.rest.action.RestStatusToXContentListener)11 Arrays.asList (java.util.Arrays.asList)10 Collections.unmodifiableList (java.util.Collections.unmodifiableList)10 POST (org.opensearch.rest.RestRequest.Method.POST)7 GET (org.opensearch.rest.RestRequest.Method.GET)6 RestActions (org.opensearch.rest.action.RestActions)5 ActiveShardCount (org.opensearch.action.support.ActiveShardCount)4 Strings (org.opensearch.common.Strings)4 FetchSourceContext (org.opensearch.search.fetch.subphase.FetchSourceContext)4 Collections (java.util.Collections)3 Set (java.util.Set)3 DocWriteRequest (org.opensearch.action.DocWriteRequest)3 VersionType (org.opensearch.index.VersionType)3 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2