Search in sources :

Example 1 with ScrollQuerySearchResult

use of org.opensearch.search.query.ScrollQuerySearchResult in project OpenSearch by opensearch-project.

the class SearchService method executeQueryPhase.

public void executeQueryPhase(InternalScrollSearchRequest request, SearchShardTask task, ActionListener<ScrollQuerySearchResult> 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.searcher().setAggregatedDfs(readerContext.getAggregatedDfs(null));
            processScroll(request, readerContext, searchContext);
            queryPhase.execute(searchContext);
            executor.success();
            readerContext.setRescoreDocIds(searchContext.rescoreDocIds());
            return new ScrollQuerySearchResult(searchContext.queryResult(), searchContext.shardTarget());
        } catch (Exception e) {
            logger.trace("Query 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) LegacyReaderContext(org.opensearch.search.internal.LegacyReaderContext) SearchContext(org.opensearch.search.internal.SearchContext) Releasable(org.opensearch.common.lease.Releasable) ScrollQuerySearchResult(org.opensearch.search.query.ScrollQuerySearchResult) 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)

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 LegacyReaderContext (org.opensearch.search.internal.LegacyReaderContext)1 SearchContext (org.opensearch.search.internal.SearchContext)1 ShardSearchRequest (org.opensearch.search.internal.ShardSearchRequest)1 ScrollQuerySearchResult (org.opensearch.search.query.ScrollQuerySearchResult)1