Search in sources :

Example 1 with ScrollQueryFetchSearchResult

use of org.opensearch.search.fetch.ScrollQueryFetchSearchResult in project OpenSearch by opensearch-project.

the class SearchService method executeFetchPhase.

public void executeFetchPhase(InternalScrollSearchRequest request, SearchShardTask task, ActionListener<ScrollQueryFetchSearchResult> listener) {
    final LegacyReaderContext readerContext = (LegacyReaderContext) findReaderContext(request.contextId(), request);
    final Releasable markAsUsed;
    try {
        markAsUsed = readerContext.markAsUsed(getScrollKeepAlive(request.scroll()));
    } catch (Exception e) {
        // We need to release the reader context of the scroll when we hit any exception (here the keep_alive can be too large)
        freeReaderContext(readerContext.id());
        throw e;
    }
    runAsync(getExecutor(readerContext.indexShard()), () -> {
        final ShardSearchRequest shardSearchRequest = readerContext.getShardSearchRequest(null);
        try (SearchContext searchContext = createContext(readerContext, shardSearchRequest, task, false);
            SearchOperationListenerExecutor executor = new SearchOperationListenerExecutor(searchContext)) {
            searchContext.assignRescoreDocIds(readerContext.getRescoreDocIds(null));
            searchContext.searcher().setAggregatedDfs(readerContext.getAggregatedDfs(null));
            processScroll(request, readerContext, searchContext);
            queryPhase.execute(searchContext);
            final long afterQueryTime = executor.success();
            QueryFetchSearchResult fetchSearchResult = executeFetchPhase(readerContext, searchContext, afterQueryTime);
            return new ScrollQueryFetchSearchResult(fetchSearchResult, searchContext.shardTarget());
        } catch (Exception e) {
            assert TransportActions.isShardNotAvailableException(e) == false : new AssertionError(e);
            logger.trace("Fetch phase failed", e);
            // we handle the failure in the failure listener below
            throw e;
        }
    }, wrapFailureListener(listener, readerContext, markAsUsed));
}
Also used : ShardSearchRequest(org.opensearch.search.internal.ShardSearchRequest) ScrollQueryFetchSearchResult(org.opensearch.search.fetch.ScrollQueryFetchSearchResult) QueryFetchSearchResult(org.opensearch.search.fetch.QueryFetchSearchResult) LegacyReaderContext(org.opensearch.search.internal.LegacyReaderContext) SearchContext(org.opensearch.search.internal.SearchContext) Releasable(org.opensearch.common.lease.Releasable) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) AggregationInitializationException(org.opensearch.search.aggregations.AggregationInitializationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) OpenSearchException(org.opensearch.OpenSearchException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ScrollQueryFetchSearchResult(org.opensearch.search.fetch.ScrollQueryFetchSearchResult)

Aggregations

IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 OpenSearchException (org.opensearch.OpenSearchException)1 Releasable (org.opensearch.common.lease.Releasable)1 OpenSearchRejectedExecutionException (org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)1 IndexNotFoundException (org.opensearch.index.IndexNotFoundException)1 AggregationInitializationException (org.opensearch.search.aggregations.AggregationInitializationException)1 QueryFetchSearchResult (org.opensearch.search.fetch.QueryFetchSearchResult)1 ScrollQueryFetchSearchResult (org.opensearch.search.fetch.ScrollQueryFetchSearchResult)1 LegacyReaderContext (org.opensearch.search.internal.LegacyReaderContext)1 SearchContext (org.opensearch.search.internal.SearchContext)1 ShardSearchRequest (org.opensearch.search.internal.ShardSearchRequest)1