- All Implemented Interfaces:
Closeable,AutoCloseable,LifecycleComponent,Releasable,IndexEventListener
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumUsed to indicate which result object should be instantiated when creating a search context -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intEnables low-level, frequent search cancellation checks.static final Setting<ByteSizeValue> static final Setting<ByteSizeValue> The size of the buffer used for memory accounting.static final TimeValueFields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle -
Constructor Summary
ConstructorsConstructorDescriptionSearchService(ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase, CircuitBreakerService circuitBreakerService, ExecutorSelector executorSelector, Tracer tracer, OnlinePrewarmingService onlinePrewarmingService) -
Method Summary
Modifier and TypeMethodDescriptionvoidafterIndexRemoved(Index index, IndexSettings indexSettings, IndexRemovalReason reason) Called after the index has been removed.aggReduceContextBuilder(Supplier<Boolean> isCanceled, AggregatorFactories.Builder aggs) Returns a builder forAggregationReduceContext.booleanvoidbeforeIndexShardCreated(ShardRouting routing, Settings indexSettings) Called before the index shard gets created, before obtaining the shard lock.buildAliasFilter(ProjectState state, String index, Set<IndexNameExpressionResolver.ResolvedExpression> resolvedExpressions) voidcanMatch(CanMatchNodeRequest request, ActionListener<CanMatchNodeResponse> listener) 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.static booleanReturns true iff the given search source builder can be early terminated by rewriting to a match none query.protected voidprotected SearchContextcreateContext(ReaderContext readerContext, ShardSearchRequest request, CancellableTask task, SearchService.ResultsType resultsType, boolean includeAggregations) createSearchContext(ShardSearchRequest request, TimeValue timeout) booleanprotected voiddoClose()Close this component.protected voiddoStart()Start this component.protected voiddoStop()Stop this component.voidexecuteDfsPhase(ShardSearchRequest request, SearchShardTask task, ActionListener<SearchPhaseResult> listener) voidexecuteFetchPhase(ShardFetchRequest request, CancellableTask task, ActionListener<FetchSearchResult> listener) voidexecuteFetchPhase(InternalScrollSearchRequest request, SearchShardTask task, ActionListener<ScrollQueryFetchSearchResult> listener) voidexecuteQueryPhase(InternalScrollSearchRequest request, SearchShardTask task, ActionListener<ScrollQuerySearchResult> listener, TransportVersion version) voidexecuteQueryPhase(ShardSearchRequest request, CancellableTask task, ActionListener<SearchPhaseResult> listener) voidexecuteQueryPhase(QuerySearchRequest request, SearchShardTask task, ActionListener<QuerySearchResult> listener, TransportVersion version) The returnedSearchPhaseResultwill have had its ref count incremented by this method.voidexecuteRankFeaturePhase(RankFeatureShardRequest request, SearchShardTask task, ActionListener<RankFeatureResult> listener) voidbooleanfreeReaderContext(ShardSearchContextId contextId) intReturns the number of active contexts in this SearchServicegetCoordinatorRewriteContextProvider(LongSupplier nowInMillis) longintReturns the number of scroll contexts opened on the nodegetRewriteContext(LongSupplier nowInMillis, ResolvedIndices resolvedIndices, PointInTimeBuilder pit) Returns a newQueryRewriteContextwith the givennowprovidergetRewriteContext(LongSupplier nowInMillis, ResolvedIndices resolvedIndices, PointInTimeBuilder pit, boolean isExplain) Returns a newQueryRewriteContextwith the givennowprovidervoidopenReaderContext(ShardId shardId, TimeValue keepAlive, ActionListener<ShardSearchContextId> listener) Opens the reader context for given shardId.protected voidputReaderContext(ReaderContext context) static booleanqueryStillMatchesAfterRewrite(ShardSearchRequest request, QueryRewriteContext context) This method tries to rewrite a query without using aSearchExecutionContext.protected ReaderContextremoveReaderContext(long id) Methods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.elasticsearch.index.shard.IndexEventListener
afterFilesRestoredFromRepository, afterIndexCreated, afterIndexShardClosed, afterIndexShardClosing, afterIndexShardCreated, afterIndexShardDeleted, afterIndexShardRecovery, afterIndexShardStarted, beforeIndexAddedToCluster, beforeIndexCreated, beforeIndexRemoved, beforeIndexShardClosed, beforeIndexShardDeleted, beforeIndexShardMutableOperation, beforeIndexShardRecovery, indexShardStateChanged, onStoreClosed, onStoreCreated, shardRoutingChanged
-
Field Details
-
DEFAULT_KEEPALIVE_SETTING
-
MAX_KEEPALIVE_SETTING
-
KEEPALIVE_INTERVAL_SETTING
-
ALLOW_EXPENSIVE_QUERIES
-
CCS_VERSION_CHECK_SETTING
-
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
-
DEFAULT_SEARCH_TIMEOUT_SETTING
-
DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS
-
MINIMUM_DOCS_PER_SLICE
-
SEARCH_WORKER_THREADS_ENABLED
-
QUERY_PHASE_PARALLEL_COLLECTION_ENABLED
-
MAX_OPEN_SCROLL_CONTEXT
-
ENABLE_REWRITE_AGGS_TO_FILTER_BY_FILTER
-
MAX_ASYNC_SEARCH_RESPONSE_SIZE_SETTING
-
CCS_COLLECT_TELEMETRY
-
BATCHED_QUERY_PHASE
-
PREWARMING_THRESHOLD_THREADPOOL_SIZE_FACTOR_POOL_SIZE
-
MEMORY_ACCOUNTING_BUFFER_SIZE
The size of the buffer used for memory accounting. This buffer is used to locally track the memory accummulated during the execution of a search request before submitting the accumulated value to the circuit breaker. -
DEFAULT_SIZE
public static final int DEFAULT_SIZE- See Also:
-
DEFAULT_FROM
public static final int DEFAULT_FROM- See Also:
-
-
Constructor Details
-
SearchService
public SearchService(ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase, CircuitBreakerService circuitBreakerService, ExecutorSelector executorSelector, Tracer tracer, OnlinePrewarmingService onlinePrewarmingService)
-
-
Method Details
-
getCircuitBreaker
-
defaultAllowPartialSearchResults
public boolean defaultAllowPartialSearchResults() -
batchQueryPhase
public boolean batchQueryPhase() -
afterIndexRemoved
Description copied from interface:IndexEventListenerCalled after the index has been removed.- Specified by:
afterIndexRemovedin interfaceIndexEventListener- Parameters:
index- The indexreason- the reason for index removal
-
beforeIndexShardCreated
Description copied from interface:IndexEventListenerCalled before the index shard gets created, before obtaining the shard lock.- Specified by:
beforeIndexShardCreatedin interfaceIndexEventListener- Parameters:
routing- the routing entry that caused the shard to be created.indexSettings- the shards index settings
-
putReaderContext
-
removeReaderContext
-
doStart
protected void doStart()Description copied from class:AbstractLifecycleComponentStart this component. Typically that means doing things like launching background processes and registering listeners on other components. Other components have been initialized by this point, but may not yet be started.If this method throws an exception then the startup process will fail, but this component will not be stopped before it is closed.
This method is called while synchronized on
AbstractLifecycleComponent.lifecycle. It is only called once in the lifetime of a component, although it may not be called at all if the startup process encountered some kind of fatal error, such as the failure of some other component to initialize or start.- Specified by:
doStartin classAbstractLifecycleComponent
-
doStop
protected void doStop()Description copied from class:AbstractLifecycleComponentStop this component. Typically that means doing the reverse of whateverAbstractLifecycleComponent.doStart()does.This method is called while synchronized on
AbstractLifecycleComponent.lifecycle. It is only called once in the lifetime of a component, after callingAbstractLifecycleComponent.doStart(), although it will not be called at all if this component did not successfully start.- Specified by:
doStopin classAbstractLifecycleComponent
-
doClose
protected void doClose()Description copied from class:AbstractLifecycleComponentClose this component. Typically that means doing the reverse of whatever happened during initialization, such as releasing resources acquired there.This method is called while synchronized on
AbstractLifecycleComponent.lifecycle. It is called once in the lifetime of a component. If the component was started then it will be stopped before it is closed, and once it is closed it will not be started or stopped.- Specified by:
doClosein classAbstractLifecycleComponent
-
executeDfsPhase
public void executeDfsPhase(ShardSearchRequest request, SearchShardTask task, ActionListener<SearchPhaseResult> listener) -
executeQueryPhase
public void executeQueryPhase(ShardSearchRequest request, CancellableTask task, ActionListener<SearchPhaseResult> listener) -
executeRankFeaturePhase
public void executeRankFeaturePhase(RankFeatureShardRequest request, SearchShardTask task, ActionListener<RankFeatureResult> listener) -
executeQueryPhase
public void executeQueryPhase(InternalScrollSearchRequest request, SearchShardTask task, ActionListener<ScrollQuerySearchResult> listener, TransportVersion version) -
executeQueryPhase
public void executeQueryPhase(QuerySearchRequest request, SearchShardTask task, ActionListener<QuerySearchResult> listener, TransportVersion version) The returnedSearchPhaseResultwill have had its ref count incremented by this method. It is the responsibility of the caller to ensure that the ref count is correctly decremented when the object is no longer needed. -
executeFetchPhase
public void executeFetchPhase(InternalScrollSearchRequest request, SearchShardTask task, ActionListener<ScrollQueryFetchSearchResult> listener) -
executeFetchPhase
public void executeFetchPhase(ShardFetchRequest request, CancellableTask task, ActionListener<FetchSearchResult> listener) -
checkCancelled
-
openReaderContext
public void openReaderContext(ShardId shardId, TimeValue keepAlive, ActionListener<ShardSearchContextId> listener) Opens the reader context for given shardId. The newly opened reader context will be keep until thekeepAliveelapsed unless it is manually released. -
createContext
protected SearchContext createContext(ReaderContext readerContext, ShardSearchRequest request, CancellableTask task, SearchService.ResultsType resultsType, boolean includeAggregations) throws IOException - Throws:
IOException
-
createSearchContext
public SearchContext createSearchContext(ShardSearchRequest request, 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 -
getDefaultKeepAliveInMillis
public long getDefaultKeepAliveInMillis() -
buildAliasFilter
public AliasFilter buildAliasFilter(ProjectState state, String index, Set<IndexNameExpressionResolver.ResolvedExpression> resolvedExpressions) -
canMatch
-
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 returnsfalsethe query won't match any documents on the current shard. Exceptions are handled within the method, and never re-thrown. -
queryStillMatchesAfterRewrite
public static boolean queryStillMatchesAfterRewrite(ShardSearchRequest request, QueryRewriteContext context) throws IOException This method tries to rewrite a query without using aSearchExecutionContext. It takes advantage of the fact that we can skip some shards in the query phase because we have enough information in the index mapping to decide the 'can match' outcome. One such example is a term based query against a constant keyword field. This queries can rewrite themselves to aMatchNoneQueryBuilder. This allows us to avoid extra work for example making the shard search active and waiting for refreshes.- 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
public QueryRewriteContext getRewriteContext(LongSupplier nowInMillis, ResolvedIndices resolvedIndices, PointInTimeBuilder pit) Returns a newQueryRewriteContextwith the givennowprovider -
getRewriteContext
public QueryRewriteContext getRewriteContext(LongSupplier nowInMillis, ResolvedIndices resolvedIndices, PointInTimeBuilder pit, boolean isExplain) Returns a newQueryRewriteContextwith the givennowprovider -
getCoordinatorRewriteContextProvider
public CoordinatorRewriteContextProvider getCoordinatorRewriteContextProvider(LongSupplier nowInMillis) -
getIndicesService
-
aggReduceContextBuilder
public AggregationReduceContext.Builder aggReduceContextBuilder(Supplier<Boolean> isCanceled, AggregatorFactories.Builder aggs) Returns a builder forAggregationReduceContext.
-