- All Implemented Interfaces:
Closeable
,AutoCloseable
,LifecycleComponent
,Releasable
,IndexEventListener
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static enum
Used to indicate which result object should be instantiated when creating a search context -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
Enables low-level, frequent search cancellation checks.static final Setting<ByteSizeValue>
static final 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, Tracer tracer) -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterIndexRemoved
(Index index, IndexSettings indexSettings, IndicesClusterStateService.AllocatedIndices.IndexRemovalReason reason) Called after the index has been removed.aggReduceContextBuilder
(Supplier<Boolean> isCanceled, AggregatorFactories.Builder aggs) Returns a builder forAggregationReduceContext
.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) void
canMatch
(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 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, SearchService.ResultsType resultsType, boolean includeAggregations) createSearchContext
(ShardSearchRequest request, TimeValue timeout) boolean
protected void
doClose()
Close this component.protected void
doStart()
Start this component.protected void
doStop()
Stop this component.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) The returnedSearchPhaseResult
will have had its ref count incremented by this method.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, 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, 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
afterFilesRestoredFromRepository, afterIndexCreated, afterIndexShardClosed, afterIndexShardCreated, afterIndexShardDeleted, afterIndexShardRecovery, afterIndexShardStarted, beforeIndexAddedToCluster, beforeIndexCreated, beforeIndexRemoved, beforeIndexShardClosed, beforeIndexShardDeleted, 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
-
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, ResponseCollectorService responseCollectorService, CircuitBreakerService circuitBreakerService, ExecutorSelector executorSelector, Tracer tracer)
-
-
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()Description copied from class:AbstractLifecycleComponent
Start 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:
doStart
in classAbstractLifecycleComponent
-
doStop
protected void doStop()Description copied from class:AbstractLifecycleComponent
Stop 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:
doStop
in classAbstractLifecycleComponent
-
doClose
protected void doClose()Description copied from class:AbstractLifecycleComponent
Close 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:
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) The returnedSearchPhaseResult
will 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, SearchShardTask 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 thekeepAlive
elapsed unless it is manually released. -
createContext
protected SearchContext createContext(ReaderContext readerContext, ShardSearchRequest request, SearchShardTask 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 -
getResponseCollectorService
-
buildAliasFilter
public AliasFilter buildAliasFilter(ClusterState state, String index, Set<String> 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 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
public AggregationReduceContext.Builder aggReduceContextBuilder(Supplier<Boolean> isCanceled, AggregatorFactories.Builder aggs) Returns a builder forAggregationReduceContext
.
-