Package org.elasticsearch.search
Class SearchService
java.lang.Object
org.elasticsearch.common.component.AbstractLifecycleComponent
org.elasticsearch.search.SearchService
- All Implemented Interfaces:
Closeable
,AutoCloseable
,LifecycleComponent
,org.elasticsearch.core.Releasable
,IndexEventListener
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic int
static Setting<org.elasticsearch.core.TimeValue>
static Setting<org.elasticsearch.core.TimeValue>
static int
static Setting<org.elasticsearch.core.TimeValue>
Enables low-level, frequent search cancellation checks.static Setting<org.elasticsearch.core.TimeValue>
static org.elasticsearch.core.TimeValue
Fields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle
-
Constructor Summary
ConstructorDescriptionSearchService(ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase, ResponseCollectorService responseCollectorService, CircuitBreakerService circuitBreakerService, ExecutorSelector executorSelector)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterIndexRemoved(Index index, IndexSettings indexSettings, IndicesClusterStateService.AllocatedIndices.IndexRemovalReason reason)
Called after the index has been removed.aggReduceContextBuilder(SearchRequest request)
Returns a builder forInternalAggregation.ReduceContext
.void
beforeIndexShardCreated(ShardRouting routing, Settings indexSettings)
Called before the index shard gets created, before obtaining the shard lock.buildAliasFilter(ClusterState state, String index, Set<String> resolvedExpressions)
canMatch(ShardSearchRequest request)
This method uses a lightweight searcher without wrapping (i.e., not open a full reader on frozen indices) to rewrite the query to check if the query can match any documents.void
canMatch(ShardSearchRequest request, ActionListener<SearchService.CanMatchResponse> listener)
static boolean
Returns true iff the given search source builder can be early terminated by rewriting to a match none query.protected void
protected SearchContext
createContext(ReaderContext readerContext, ShardSearchRequest request, SearchShardTask task, boolean includeAggregations)
org.elasticsearch.search.DefaultSearchContext
createSearchContext(ShardSearchRequest request, org.elasticsearch.core.TimeValue timeout)
boolean
protected void
doClose()
protected void
doStart()
protected void
doStop()
void
executeDfsPhase(ShardSearchRequest request, SearchShardTask task, ActionListener<SearchPhaseResult> listener)
void
executeFetchPhase(ShardFetchRequest request, SearchShardTask task, ActionListener<FetchSearchResult> listener)
void
executeFetchPhase(InternalScrollSearchRequest request, SearchShardTask task, ActionListener<ScrollQueryFetchSearchResult> listener)
void
executeQueryPhase(InternalScrollSearchRequest request, SearchShardTask task, ActionListener<ScrollQuerySearchResult> listener)
void
executeQueryPhase(ShardSearchRequest request, SearchShardTask task, ActionListener<SearchPhaseResult> listener)
void
executeQueryPhase(QuerySearchRequest request, SearchShardTask task, ActionListener<QuerySearchResult> listener)
void
boolean
freeReaderContext(ShardSearchContextId contextId)
int
Returns the number of active contexts in this SearchServicegetCoordinatorRewriteContextProvider(LongSupplier nowInMillis)
int
Returns the number of scroll contexts opened on the nodegetRewriteContext(LongSupplier nowInMillis)
Returns a newQueryRewriteContext
with the givennow
providervoid
openReaderContext(ShardId shardId, org.elasticsearch.core.TimeValue keepAlive, ActionListener<ShardSearchContextId> listener)
Opens the reader context for given shardId.protected void
putReaderContext(ReaderContext context)
static boolean
queryStillMatchesAfterRewrite(ShardSearchRequest request, QueryRewriteContext context)
protected ReaderContext
removeReaderContext(long id)
Methods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.elasticsearch.index.shard.IndexEventListener
afterIndexCreated, afterIndexShardClosed, afterIndexShardCreated, afterIndexShardDeleted, afterIndexShardStarted, beforeIndexAddedToCluster, beforeIndexCreated, beforeIndexRemoved, beforeIndexShardClosed, beforeIndexShardDeleted, beforeIndexShardRecovery, indexShardStateChanged, onShardInactive, onStoreClosed, onStoreCreated, shardRoutingChanged
-
Field Details
-
DEFAULT_KEEPALIVE_SETTING
-
MAX_KEEPALIVE_SETTING
-
KEEPALIVE_INTERVAL_SETTING
-
ALLOW_EXPENSIVE_QUERIES
-
LOW_LEVEL_CANCELLATION_SETTING
Enables low-level, frequent search cancellation checks. Enabling low-level checks will make long running searches to react to the cancellation request faster. It will produce more cancellation checks but benchmarking has shown these did not noticeably slow down searches. -
NO_TIMEOUT
public static final org.elasticsearch.core.TimeValue NO_TIMEOUT -
DEFAULT_SEARCH_TIMEOUT_SETTING
-
DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS
-
MAX_OPEN_SCROLL_CONTEXT
-
ENABLE_REWRITE_AGGS_TO_FILTER_BY_FILTER
-
DEFAULT_SIZE
public static final int DEFAULT_SIZE- See Also:
- Constant Field Values
-
DEFAULT_FROM
public static final int DEFAULT_FROM- See Also:
- Constant Field Values
-
-
Constructor Details
-
SearchService
public SearchService(ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase, ResponseCollectorService responseCollectorService, CircuitBreakerService circuitBreakerService, ExecutorSelector executorSelector)
-
-
Method Details
-
defaultAllowPartialSearchResults
public boolean defaultAllowPartialSearchResults() -
afterIndexRemoved
public void afterIndexRemoved(Index index, IndexSettings indexSettings, IndicesClusterStateService.AllocatedIndices.IndexRemovalReason reason)Description copied from interface:IndexEventListener
Called after the index has been removed.- Specified by:
afterIndexRemoved
in interfaceIndexEventListener
- Parameters:
index
- The indexreason
- the reason for index removal
-
beforeIndexShardCreated
Description copied from interface:IndexEventListener
Called before the index shard gets created, before obtaining the shard lock.- Specified by:
beforeIndexShardCreated
in interfaceIndexEventListener
- Parameters:
routing
- the routing entry that caused the shard to be created.indexSettings
- the shards index settings
-
putReaderContext
-
removeReaderContext
-
doStart
protected void doStart()- Specified by:
doStart
in classAbstractLifecycleComponent
-
doStop
protected void doStop()- Specified by:
doStop
in classAbstractLifecycleComponent
-
doClose
protected void doClose()- Specified by:
doClose
in classAbstractLifecycleComponent
-
executeDfsPhase
public void executeDfsPhase(ShardSearchRequest request, SearchShardTask task, ActionListener<SearchPhaseResult> listener) -
executeQueryPhase
public void executeQueryPhase(ShardSearchRequest request, SearchShardTask task, ActionListener<SearchPhaseResult> listener) -
executeQueryPhase
public void executeQueryPhase(InternalScrollSearchRequest request, SearchShardTask task, ActionListener<ScrollQuerySearchResult> listener) -
executeQueryPhase
public void executeQueryPhase(QuerySearchRequest request, SearchShardTask task, ActionListener<QuerySearchResult> listener) -
executeFetchPhase
public void executeFetchPhase(InternalScrollSearchRequest request, SearchShardTask task, ActionListener<ScrollQueryFetchSearchResult> listener) -
executeFetchPhase
public void executeFetchPhase(ShardFetchRequest request, SearchShardTask task, ActionListener<FetchSearchResult> listener) -
checkCancelled
-
openReaderContext
public void openReaderContext(ShardId shardId, org.elasticsearch.core.TimeValue keepAlive, ActionListener<ShardSearchContextId> listener)Opens the reader context for given shardId. The newly opened reader context will be keep until thekeepAlive
elapsed unless it is manually released. -
createContext
protected SearchContext createContext(ReaderContext readerContext, ShardSearchRequest request, SearchShardTask task, boolean includeAggregations) throws IOException- Throws:
IOException
-
createSearchContext
public org.elasticsearch.search.DefaultSearchContext createSearchContext(ShardSearchRequest request, org.elasticsearch.core.TimeValue timeout) throws IOException- Throws:
IOException
-
freeReaderContext
-
freeAllScrollContexts
public void freeAllScrollContexts() -
getActiveContexts
public int getActiveContexts()Returns the number of active contexts in this SearchService -
getOpenScrollContexts
public int getOpenScrollContexts()Returns the number of scroll contexts opened on the node -
getResponseCollectorService
-
buildAliasFilter
public AliasFilter buildAliasFilter(ClusterState state, String index, Set<String> resolvedExpressions) -
canMatch
public void canMatch(ShardSearchRequest request, ActionListener<SearchService.CanMatchResponse> listener) -
canMatch
This method uses a lightweight searcher without wrapping (i.e., not open a full reader on frozen indices) to rewrite the query to check if the query can match any documents. This method can have false positives while if it returnsfalse
the query won't match any documents on the current shard.- Throws:
IOException
-
queryStillMatchesAfterRewrite
public static boolean queryStillMatchesAfterRewrite(ShardSearchRequest request, QueryRewriteContext context) throws IOException- Throws:
IOException
-
canRewriteToMatchNone
Returns true iff the given search source builder can be early terminated by rewriting to a match none query. Or in other words if the execution of the search request can be early terminated without executing it. This is for instance not possible if a global aggregation is part of this request or if there is a suggest builder present. -
getRewriteContext
Returns a newQueryRewriteContext
with the givennow
provider -
getCoordinatorRewriteContextProvider
public CoordinatorRewriteContextProvider getCoordinatorRewriteContextProvider(LongSupplier nowInMillis) -
getIndicesService
-
aggReduceContextBuilder
Returns a builder forInternalAggregation.ReduceContext
. This builder retains a reference to the providedSearchRequest
.
-