Package org.opensearch.search
Class SearchService
java.lang.Object
org.opensearch.common.lifecycle.AbstractLifecycleComponent
org.opensearch.search.SearchService
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.opensearch.common.lease.Releasable
,org.opensearch.common.lifecycle.LifecycleComponent
,IndexEventListener
public class SearchService
extends org.opensearch.common.lifecycle.AbstractLifecycleComponent
implements IndexEventListener
The main search service
- Opensearch.internal:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Search phase result that can match a response -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final int
static final String
static final int
static final Setting
<org.opensearch.common.unit.TimeValue> static final Setting
<org.opensearch.common.unit.TimeValue> static final int
static final Setting
<org.opensearch.common.unit.TimeValue> Enables low-level, frequent search cancellation checks.static final Setting
<org.opensearch.common.unit.TimeValue> This setting defines the maximum number of active PIT reader contexts in the node , since each PIT context has a resource cost attached to it.static final Setting
<org.opensearch.common.unit.TimeValue> This setting will help validate the max keep alive that can be set during creation or extension for a PIT reader contextstatic final org.opensearch.common.unit.TimeValue
Fields inherited from class org.opensearch.common.lifecycle.AbstractLifecycleComponent
lifecycle
-
Constructor Summary
ConstructorDescriptionSearchService
(ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, QueryPhase queryPhase, FetchPhase fetchPhase, ResponseCollectorService responseCollectorService, org.opensearch.core.indices.breaker.CircuitBreakerService circuitBreakerService, Executor indexSearcherExecutor, TaskResourceTrackingService taskResourceTrackingService, Collection<ConcurrentSearchRequestDecider.Factory> concurrentSearchDeciderFactories) -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterIndexRemoved
(org.opensearch.core.index.Index index, IndexSettings indexSettings, IndicesClusterStateService.AllocatedIndices.IndexRemovalReason reason) Called after the index has been removed.aggReduceContextBuilder
(SearchSourceBuilder searchSourceBuilder) Returns a builder forInternalAggregation.ReduceContext
.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, org.opensearch.core.action.ActionListener<SearchService.CanMatchResponse> listener) static boolean
canMatchSearchAfter
(org.apache.lucene.search.FieldDoc searchAfter, MinAndMax<?> minMax, FieldSortBuilder primarySortField, Integer trackTotalHitsUpto) static boolean
Returns true iff the given search source builder can be early terminated by rewriting to a match none query.void
createPitReaderContext
(org.opensearch.core.index.shard.ShardId shardId, org.opensearch.common.unit.TimeValue keepAlive, org.opensearch.core.action.ActionListener<ShardSearchContextId> listener) Opens the reader context for given shardId.org.opensearch.search.DefaultSearchContext
createSearchContext
(ShardSearchRequest request, org.opensearch.common.unit.TimeValue timeout) org.opensearch.search.DefaultSearchContext
createSearchContext
(ShardSearchRequest request, org.opensearch.common.unit.TimeValue timeout, boolean validate) org.opensearch.search.DefaultSearchContext
createValidationContext
(ShardSearchRequest request, org.opensearch.common.unit.TimeValue timeout) boolean
protected void
doClose()
protected void
doStart()
protected void
doStop()
void
executeDfsPhase
(ShardSearchRequest request, boolean keepStatesInContext, SearchShardTask task, org.opensearch.core.action.ActionListener<SearchPhaseResult> listener) void
executeFetchPhase
(ShardFetchRequest request, SearchShardTask task, org.opensearch.core.action.ActionListener<FetchSearchResult> listener) void
executeFetchPhase
(InternalScrollSearchRequest request, SearchShardTask task, org.opensearch.core.action.ActionListener<ScrollQueryFetchSearchResult> listener) void
executeQueryPhase
(InternalScrollSearchRequest request, SearchShardTask task, org.opensearch.core.action.ActionListener<ScrollQuerySearchResult> listener) void
executeQueryPhase
(ShardSearchRequest request, boolean keepStatesInContext, SearchShardTask task, org.opensearch.core.action.ActionListener<SearchPhaseResult> listener) void
executeQueryPhase
(QuerySearchRequest request, SearchShardTask task, org.opensearch.core.action.ActionListener<QuerySearchResult> listener) void
boolean
freeReaderContext
(ShardSearchContextId contextId) freeReaderContextsIfFound
(List<PitSearchContextIdForNode> contextIds) Free reader contexts if foundint
Returns the number of active contexts in this SearchServiceThis method returns all active PIT reader contextsReturns pit reader context based on IDgetRewriteContext
(LongSupplier nowInMillis) Returns a newQueryRewriteContext
with the givennow
providergetValidationRewriteContext
(LongSupplier nowInMillis) Returns a newQueryRewriteContext
for query validation with the givennow
providerprotected void
putReaderContext
(ReaderContext context) protected ReaderContext
removeReaderContext
(long id) void
updatePitIdAndKeepAlive
(UpdatePitContextRequest request, org.opensearch.core.action.ActionListener<UpdatePitContextResponse> listener) Update PIT reader with pit id, keep alive and created time etcMethods inherited from class org.opensearch.common.lifecycle.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.opensearch.index.shard.IndexEventListener
afterIndexCreated, afterIndexShardClosed, afterIndexShardCreated, afterIndexShardDeleted, afterIndexShardStarted, beforeIndexAddedToCluster, beforeIndexCreated, beforeIndexRemoved, beforeIndexShardClosed, beforeIndexShardCreated, beforeIndexShardDeleted, beforeIndexShardRecovery, indexShardStateChanged, onStoreClosed, onStoreCreated, shardRoutingChanged
-
Field Details
-
DEFAULT_KEEPALIVE_SETTING
-
MAX_PIT_KEEPALIVE_SETTING
This setting will help validate the max keep alive that can be set during creation or extension for a PIT reader context -
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.opensearch.common.unit.TimeValue NO_TIMEOUT -
DEFAULT_SEARCH_TIMEOUT_SETTING
-
DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS
-
MAX_OPEN_SCROLL_CONTEXT
-
MAX_OPEN_PIT_CONTEXT
This setting defines the maximum number of active PIT reader contexts in the node , since each PIT context has a resource cost attached to it. This setting is less than scroll since users are encouraged to share the PIT details. -
CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING
-
CONCURRENT_SEGMENT_SEARCH_MODE_ALL
- See Also:
-
CONCURRENT_SEGMENT_SEARCH_MODE_NONE
- See Also:
-
CONCURRENT_SEGMENT_SEARCH_MODE_AUTO
- See Also:
-
CLUSTER_CONCURRENT_SEGMENT_SEARCH_MODE
-
CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_KEY
- See Also:
-
CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_DEFAULT_VALUE
public static final int CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_DEFAULT_VALUE- See Also:
-
CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_SETTING
-
MAX_AGGREGATION_REWRITE_FILTERS
-
INDICES_MAX_CLAUSE_COUNT_SETTING
-
CLUSTER_ALLOW_DERIVED_FIELD_SETTING
-
CARDINALITY_AGGREGATION_PRUNING_THRESHOLD
-
KEYWORD_INDEX_OR_DOC_VALUES_ENABLED
-
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, QueryPhase queryPhase, FetchPhase fetchPhase, ResponseCollectorService responseCollectorService, org.opensearch.core.indices.breaker.CircuitBreakerService circuitBreakerService, Executor indexSearcherExecutor, TaskResourceTrackingService taskResourceTrackingService, Collection<ConcurrentSearchRequestDecider.Factory> concurrentSearchDeciderFactories)
-
-
Method Details
-
defaultAllowPartialSearchResults
public boolean defaultAllowPartialSearchResults() -
afterIndexRemoved
public void afterIndexRemoved(org.opensearch.core.index.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
-
putReaderContext
-
removeReaderContext
-
doStart
protected void doStart()- Specified by:
doStart
in classorg.opensearch.common.lifecycle.AbstractLifecycleComponent
-
doStop
protected void doStop()- Specified by:
doStop
in classorg.opensearch.common.lifecycle.AbstractLifecycleComponent
-
doClose
protected void doClose()- Specified by:
doClose
in classorg.opensearch.common.lifecycle.AbstractLifecycleComponent
-
executeDfsPhase
public void executeDfsPhase(ShardSearchRequest request, boolean keepStatesInContext, SearchShardTask task, org.opensearch.core.action.ActionListener<SearchPhaseResult> listener) -
executeQueryPhase
public void executeQueryPhase(ShardSearchRequest request, boolean keepStatesInContext, SearchShardTask task, org.opensearch.core.action.ActionListener<SearchPhaseResult> listener) -
executeQueryPhase
public void executeQueryPhase(InternalScrollSearchRequest request, SearchShardTask task, org.opensearch.core.action.ActionListener<ScrollQuerySearchResult> listener) -
executeQueryPhase
public void executeQueryPhase(QuerySearchRequest request, SearchShardTask task, org.opensearch.core.action.ActionListener<QuerySearchResult> listener) -
executeFetchPhase
public void executeFetchPhase(InternalScrollSearchRequest request, SearchShardTask task, org.opensearch.core.action.ActionListener<ScrollQueryFetchSearchResult> listener) -
executeFetchPhase
public void executeFetchPhase(ShardFetchRequest request, SearchShardTask task, org.opensearch.core.action.ActionListener<FetchSearchResult> listener) -
createPitReaderContext
public void createPitReaderContext(org.opensearch.core.index.shard.ShardId shardId, org.opensearch.common.unit.TimeValue keepAlive, org.opensearch.core.action.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. -
updatePitIdAndKeepAlive
public void updatePitIdAndKeepAlive(UpdatePitContextRequest request, org.opensearch.core.action.ActionListener<UpdatePitContextResponse> listener) Update PIT reader with pit id, keep alive and created time etc -
getPitReaderContext
Returns pit reader context based on ID -
getAllPITReaderContexts
This method returns all active PIT reader contexts -
createSearchContext
public org.opensearch.search.DefaultSearchContext createSearchContext(ShardSearchRequest request, org.opensearch.common.unit.TimeValue timeout, boolean validate) throws IOException - Throws:
IOException
-
createValidationContext
public org.opensearch.search.DefaultSearchContext createValidationContext(ShardSearchRequest request, org.opensearch.common.unit.TimeValue timeout) throws IOException - Throws:
IOException
-
createSearchContext
public org.opensearch.search.DefaultSearchContext createSearchContext(ShardSearchRequest request, org.opensearch.common.unit.TimeValue timeout) throws IOException - Throws:
IOException
-
freeReaderContext
-
freeAllScrollContexts
public void freeAllScrollContexts() -
freeReaderContextsIfFound
Free reader contexts if found- Returns:
- response with list of PIT IDs deleted and if operation is successful
-
getActiveContexts
public int getActiveContexts()Returns the number of active contexts in this SearchService -
getResponseCollectorService
-
buildAliasFilter
public AliasFilter buildAliasFilter(ClusterState state, String index, Set<String> resolvedExpressions) -
canMatch
public void canMatch(ShardSearchRequest request, org.opensearch.core.action.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
-
canMatchSearchAfter
public static boolean canMatchSearchAfter(org.apache.lucene.search.FieldDoc searchAfter, MinAndMax<?> minMax, FieldSortBuilder primarySortField, Integer trackTotalHitsUpto) -
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 -
getValidationRewriteContext
Returns a newQueryRewriteContext
for query validation with the givennow
provider -
getIndicesService
-
aggReduceContextBuilder
public InternalAggregation.ReduceContextBuilder aggReduceContextBuilder(SearchSourceBuilder searchSourceBuilder) Returns a builder forInternalAggregation.ReduceContext
. This builder retains a reference to the providedSearchSourceBuilder
.
-