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:
  • Field Details

    • DEFAULT_KEEPALIVE_SETTING

      public static final Setting<org.opensearch.common.unit.TimeValue> DEFAULT_KEEPALIVE_SETTING
    • MAX_PIT_KEEPALIVE_SETTING

      public static final Setting<org.opensearch.common.unit.TimeValue> 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

      public static final Setting<org.opensearch.common.unit.TimeValue> MAX_KEEPALIVE_SETTING
    • KEEPALIVE_INTERVAL_SETTING

      public static final Setting<org.opensearch.common.unit.TimeValue> KEEPALIVE_INTERVAL_SETTING
    • ALLOW_EXPENSIVE_QUERIES

      public static final Setting<Boolean> ALLOW_EXPENSIVE_QUERIES
    • LOW_LEVEL_CANCELLATION_SETTING

      public static final Setting<Boolean> 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

      public static final Setting<org.opensearch.common.unit.TimeValue> DEFAULT_SEARCH_TIMEOUT_SETTING
    • DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS

      public static final Setting<Boolean> DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS
    • MAX_OPEN_SCROLL_CONTEXT

      public static final Setting<Integer> MAX_OPEN_SCROLL_CONTEXT
    • MAX_OPEN_PIT_CONTEXT

      public static final Setting<Integer> 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

      public static final Setting<Boolean> CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING
    • CONCURRENT_SEGMENT_SEARCH_MODE_ALL

      public static final String CONCURRENT_SEGMENT_SEARCH_MODE_ALL
      See Also:
    • CONCURRENT_SEGMENT_SEARCH_MODE_NONE

      public static final String CONCURRENT_SEGMENT_SEARCH_MODE_NONE
      See Also:
    • CONCURRENT_SEGMENT_SEARCH_MODE_AUTO

      public static final String CONCURRENT_SEGMENT_SEARCH_MODE_AUTO
      See Also:
    • CLUSTER_CONCURRENT_SEGMENT_SEARCH_MODE

      public static final Setting<String> CLUSTER_CONCURRENT_SEGMENT_SEARCH_MODE
    • CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_KEY

      public static final String 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

      public static final Setting<Integer> CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_SETTING
    • MAX_AGGREGATION_REWRITE_FILTERS

      public static final Setting<Integer> MAX_AGGREGATION_REWRITE_FILTERS
    • INDICES_MAX_CLAUSE_COUNT_SETTING

      public static final Setting<Integer> INDICES_MAX_CLAUSE_COUNT_SETTING
    • CLUSTER_ALLOW_DERIVED_FIELD_SETTING

      public static final Setting<Boolean> CLUSTER_ALLOW_DERIVED_FIELD_SETTING
    • CARDINALITY_AGGREGATION_PRUNING_THRESHOLD

      public static final Setting<Integer> CARDINALITY_AGGREGATION_PRUNING_THRESHOLD
    • KEYWORD_INDEX_OR_DOC_VALUES_ENABLED

      public static final Setting<Boolean> 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

  • 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 interface IndexEventListener
      Parameters:
      index - The index
      reason - the reason for index removal
    • putReaderContext

      protected void putReaderContext(ReaderContext context)
    • removeReaderContext

      protected ReaderContext removeReaderContext(long id)
    • doStart

      protected void doStart()
      Specified by:
      doStart in class org.opensearch.common.lifecycle.AbstractLifecycleComponent
    • doStop

      protected void doStop()
      Specified by:
      doStop in class org.opensearch.common.lifecycle.AbstractLifecycleComponent
    • doClose

      protected void doClose()
      Specified by:
      doClose in class org.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 the keepAlive 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

      public PitReaderContext getPitReaderContext(ShardSearchContextId id)
      Returns pit reader context based on ID
    • getAllPITReaderContexts

      public List<ListPitInfo> 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

      public boolean freeReaderContext(ShardSearchContextId contextId)
    • freeAllScrollContexts

      public void freeAllScrollContexts()
    • freeReaderContextsIfFound

      public DeletePitResponse freeReaderContextsIfFound(List<PitSearchContextIdForNode> contextIds)
      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

      public ResponseCollectorService 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 returns false 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

      public static boolean canRewriteToMatchNone(SearchSourceBuilder source)
      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)
      Returns a new QueryRewriteContext with the given now provider
    • getValidationRewriteContext

      public QueryRewriteContext getValidationRewriteContext(LongSupplier nowInMillis)
      Returns a new QueryRewriteContext for query validation with the given now provider
    • getIndicesService

      public IndicesService getIndicesService()
    • aggReduceContextBuilder

      public InternalAggregation.ReduceContextBuilder aggReduceContextBuilder(SearchSourceBuilder searchSourceBuilder)
      Returns a builder for InternalAggregation.ReduceContext. This builder retains a reference to the provided SearchSourceBuilder.