Search in sources :

Example 1 with RestCancellableNodeClient

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

the class RestSearchAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    SearchRequest searchRequest = new SearchRequest();
    /*
         * We have to pull out the call to `source().size(size)` because
         * _update_by_query and _delete_by_query uses this same parsing
         * path but sets a different variable when it sees the `size`
         * url parameter.
         *
         * Note that we can't use `searchRequest.source()::size` because
         * `searchRequest.source()` is null right now. We don't have to
         * guard against it being null in the IntConsumer because it can't
         * be null later. If that is confusing to you then you are in good
         * company.
         */
    IntConsumer setSize = size -> searchRequest.source().size(size);
    request.withContentOrSourceParamParserOrNull(parser -> parseSearchRequest(searchRequest, request, parser, client.getNamedWriteableRegistry(), setSize));
    return channel -> {
        RestCancellableNodeClient cancelClient = new RestCancellableNodeClient(client, request.getHttpChannel());
        cancelClient.execute(SearchAction.INSTANCE, searchRequest, new RestStatusToXContentListener<>(channel));
    };
}
Also used : SearchAction(org.opensearch.action.search.SearchAction) POST(org.opensearch.rest.RestRequest.Method.POST) Arrays(java.util.Arrays) Collections.unmodifiableList(java.util.Collections.unmodifiableList) TimeValue.parseTimeValue(org.opensearch.common.unit.TimeValue.parseTimeValue) SearchContext(org.opensearch.search.internal.SearchContext) IntConsumer(java.util.function.IntConsumer) IndicesOptions(org.opensearch.action.support.IndicesOptions) ActionRequestValidationException(org.opensearch.action.ActionRequestValidationException) Strings(org.opensearch.common.Strings) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) XContentParser(org.opensearch.common.xcontent.XContentParser) HashSet(java.util.HashSet) SortOrder(org.opensearch.search.sort.SortOrder) SuggestMode(org.opensearch.search.suggest.term.TermSuggestionBuilder.SuggestMode) Booleans(org.opensearch.common.Booleans) Arrays.asList(java.util.Arrays.asList) SearchRequest(org.opensearch.action.search.SearchRequest) RestCancellableNodeClient(org.opensearch.rest.action.RestCancellableNodeClient) BaseRestHandler(org.opensearch.rest.BaseRestHandler) Scroll(org.opensearch.search.Scroll) SearchContextId(org.opensearch.action.search.SearchContextId) NodeClient(org.opensearch.client.node.NodeClient) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) ValidateActions.addValidationError(org.opensearch.action.ValidateActions.addValidationError) ExceptionsHelper(org.opensearch.ExceptionsHelper) Set(java.util.Set) SuggestBuilders.termSuggestion(org.opensearch.search.suggest.SuggestBuilders.termSuggestion) IOException(java.io.IOException) List(java.util.List) RestActions(org.opensearch.rest.action.RestActions) SuggestBuilder(org.opensearch.search.suggest.SuggestBuilder) QueryBuilder(org.opensearch.index.query.QueryBuilder) RestStatusToXContentListener(org.opensearch.rest.action.RestStatusToXContentListener) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) StoredFieldsContext(org.opensearch.search.fetch.StoredFieldsContext) Collections(java.util.Collections) FetchSourceContext(org.opensearch.search.fetch.subphase.FetchSourceContext) SearchRequest(org.opensearch.action.search.SearchRequest) RestCancellableNodeClient(org.opensearch.rest.action.RestCancellableNodeClient) IntConsumer(java.util.function.IntConsumer) RestStatusToXContentListener(org.opensearch.rest.action.RestStatusToXContentListener)

Aggregations

IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 IntConsumer (java.util.function.IntConsumer)1 ExceptionsHelper (org.opensearch.ExceptionsHelper)1 ActionRequestValidationException (org.opensearch.action.ActionRequestValidationException)1 ValidateActions.addValidationError (org.opensearch.action.ValidateActions.addValidationError)1 SearchAction (org.opensearch.action.search.SearchAction)1 SearchContextId (org.opensearch.action.search.SearchContextId)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 IndicesOptions (org.opensearch.action.support.IndicesOptions)1 NodeClient (org.opensearch.client.node.NodeClient)1 Booleans (org.opensearch.common.Booleans)1 Strings (org.opensearch.common.Strings)1 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)1