Search in sources :

Example 6 with SearchOperationListener

use of org.elasticsearch.index.shard.SearchOperationListener in project elasticsearch by elastic.

the class SearchService method executeQueryPhase.

public QuerySearchResultProvider executeQueryPhase(ShardSearchRequest request, SearchTask task) throws IOException {
    final SearchContext context = createAndPutContext(request);
    final SearchOperationListener operationListener = context.indexShard().getSearchOperationListener();
    context.incRef();
    try {
        context.setTask(task);
        operationListener.onPreQueryPhase(context);
        long time = System.nanoTime();
        contextProcessing(context);
        loadOrExecuteQueryPhase(request, context);
        if (context.queryResult().hasHits() == false && context.scrollContext() == null) {
            freeContext(context.id());
        } else {
            contextProcessedSuccessfully(context);
        }
        final long afterQueryTime = System.nanoTime();
        operationListener.onQueryPhase(context, afterQueryTime - time);
        if (request.numberOfShards() == 1) {
            return executeFetchPhase(context, operationListener, afterQueryTime);
        }
        return context.queryResult();
    } catch (Exception e) {
        // execution exception can happen while loading the cache, strip it
        if (e instanceof ExecutionException) {
            e = (e.getCause() == null || e.getCause() instanceof Exception) ? (Exception) e.getCause() : new ElasticsearchException(e.getCause());
        }
        operationListener.onFailedQueryPhase(context);
        logger.trace("Query phase failed", e);
        processFailure(context, e);
        throw ExceptionsHelper.convertToRuntime(e);
    } finally {
        cleanContext(context);
    }
}
Also used : SearchContext(org.elasticsearch.search.internal.SearchContext) ElasticsearchException(org.elasticsearch.ElasticsearchException) SearchOperationListener(org.elasticsearch.index.shard.SearchOperationListener) ExecutionException(java.util.concurrent.ExecutionException) ElasticsearchException(org.elasticsearch.ElasticsearchException) AggregationInitializationException(org.elasticsearch.search.aggregations.AggregationInitializationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

SearchOperationListener (org.elasticsearch.index.shard.SearchOperationListener)6 SearchContext (org.elasticsearch.search.internal.SearchContext)6 IOException (java.io.IOException)5 ExecutionException (java.util.concurrent.ExecutionException)5 ElasticsearchException (org.elasticsearch.ElasticsearchException)5 AggregationInitializationException (org.elasticsearch.search.aggregations.AggregationInitializationException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AnalysisRegistry (org.elasticsearch.index.analysis.AnalysisRegistry)1 IndexShard (org.elasticsearch.index.shard.IndexShard)1 QueryFetchSearchResult (org.elasticsearch.search.fetch.QueryFetchSearchResult)1 ScrollQueryFetchSearchResult (org.elasticsearch.search.fetch.ScrollQueryFetchSearchResult)1 ScrollQuerySearchResult (org.elasticsearch.search.query.ScrollQuerySearchResult)1 TestSearchContext (org.elasticsearch.test.TestSearchContext)1