Package org.opensearch.search.internal
Class SearchContext
java.lang.Object
org.opensearch.search.internal.SearchContext
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.opensearch.common.lease.Releasable
- Direct Known Subclasses:
FilteredSearchContext
@PublicApi(since="1.0.0")
public abstract class SearchContext
extends Object
implements org.opensearch.common.lease.Releasable
This class encapsulates the state needed to execute a search. It holds a reference to the
shards point in time snapshot (IndexReader / ContextIndexSearcher) and allows passing on
state from one query / fetch phase to another.
- Opensearch.api:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final BucketCollectorProcessor
static final int
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addReleasable
(org.opensearch.common.lease.Releasable releasable) Adds a releasable that will be freed when this context is closed.abstract void
addRescore
(RescoreContext rescore) abstract void
addSearchExt
(SearchExtBuilder searchExtBuilder) abstract SearchContextAggregations
abstract SearchContext
aggregations
(SearchContextAggregations aggregations) abstract org.apache.lucene.search.Query
asLocalBucketCountThresholds
(TermsAggregator.BucketCountThresholds bucketCountThresholds) Returns local bucket count thresholds based on concurrent segment search statusfinal void
assignRescoreDocIds
(RescoreDocIds rescoreDocIds) abstract BigArrays
abstract BitsetFilterCache
abstract BucketCollectorProcessor
abstract org.apache.lucene.search.Query
buildFilteredQuery
(org.apache.lucene.search.Query query) Automatically apply all required filters to the given query such as alias filters, types filters, etc.final void
close()
abstract CollapseContext
collapse()
abstract SearchContext
collapse
(CollapseContext collapse) abstract DfsSearchResult
abstract int[]
abstract SearchContext
docIdsToLoad
(int[] docIdsToLoad, int docsIdsToLoadFrom, int docsIdsToLoadSize) abstract int
abstract int
protected abstract void
doClose()
abstract FetchDocValuesContext
abstract SearchContext
docValuesContext
(FetchDocValuesContext docValuesContext) abstract boolean
explain()
abstract void
explain
(boolean explain) abstract FetchFieldsContext
The context related to retrieving fields.abstract SearchContext
fetchFieldsContext
(FetchFieldsContext fetchFieldsContext) Sets the context related to retrieving fields.abstract FetchPhase
abstract FetchSearchResult
abstract FetchSourceContext
abstract SearchContext
fetchSourceContext
(FetchSourceContext fetchSourceContext) abstract MappedFieldType
Given the full name of a field, returns itsMappedFieldType
.abstract int
from()
abstract SearchContext
from
(int from) abstract ObjectMapper
getObjectMapper
(String name) abstract Profilers
Return a handle over the profilers for the current search request, ornull
if profiling is not enabled.abstract QueryShardContext
abstract long
Returns time in milliseconds that can be used for relative time calculations.long
getRelativeTimeInMillis
(boolean useCache) Returns time in milliseconds that can be used for relative time calculations.abstract SearchExtBuilder
getSearchExt
(String name) abstract int
abstract SearchShardTask
getTask()
abstract void
groupStats
(List<String> groupStats) abstract boolean
boolean
final boolean
abstract boolean
abstract boolean
abstract boolean
abstract SearchHighlightContext
abstract void
highlight
(SearchHighlightContext highlight) abstract ShardSearchContextId
id()
boolean
Checks if scores from named queries are included in the search results.includeNamedQueriesScore
(boolean includeNamedQueriesScore) Determines whether named queries' scores should be included in the search results.abstract IndexShard
abstract boolean
boolean
abstract boolean
Indicates if the current index should perform frequent low level search cancellation check.abstract MapperService
int
abstract Float
abstract SearchContext
minimumScore
(float minimumScore) abstract int
abstract ParsedQuery
abstract SearchContext
parsedPostFilter
(ParsedQuery postFilter) abstract ParsedQuery
abstract SearchContext
parsedQuery
(ParsedQuery query) abstract InternalAggregation.ReduceContext
abstract void
preProcess
(boolean rewrite) Should be called before executing the main query and after all other parameters have been set.abstract org.apache.lucene.search.Query
query()
The query to execute, might be rewritten.abstract float
abstract Map
<Class<?>, org.apache.lucene.search.CollectorManager<? extends org.apache.lucene.search.Collector, ReduceableSearchResult>> Return a view of the additional query collector managers that should be run for this context.abstract QuerySearchResult
abstract ReaderContext
abstract ShardSearchRequest
request()
abstract List
<RescoreContext> rescore()
final RescoreDocIds
abstract ScriptFieldsContext
abstract ScrollContext
abstract org.apache.lucene.search.FieldDoc
abstract SearchContext
searchAfter
(org.apache.lucene.search.FieldDoc searchAfter) abstract ContextIndexSearcher
searcher()
abstract SearchType
abstract boolean
indicates whether the sequence number and primary term of the last modification to each hit should be returnedabstract void
seqNoAndPrimaryTerm
(boolean seqNoAndPrimaryTerm) controls whether the sequence number and primary term of the last modification to each hit should be returnedabstract void
setBucketCollectorProcessor
(BucketCollectorProcessor bucketCollectorProcessor) void
setSearchTimedOut
(boolean searchTimedOut) abstract void
setTask
(SearchShardTask task) abstract SearchShardTarget
boolean
Returns concurrent segment search status for the search contextabstract boolean
abstract SimilarityService
abstract int
size()
abstract SearchContext
size
(int size) abstract SortAndFormats
sort()
abstract SearchContext
sort
(SortAndFormats sort) abstract String
source()
abstract boolean
A shortcut function to see whether there is a fetchSourceContext and it says the source is requested.abstract StoredFieldsContext
abstract SearchContext
storedFieldsContext
(StoredFieldsContext storedFieldsContext) abstract boolean
A shortcut function to see whether there is a storedFieldsContext and it says the fields are requested.abstract SuggestionSearchContext
suggest()
abstract void
suggest
(SuggestionSearchContext suggest) abstract int
abstract void
terminateAfter
(int terminateAfter) abstract org.opensearch.common.unit.TimeValue
timeout()
abstract void
timeout
(org.opensearch.common.unit.TimeValue timeout) toString()
abstract boolean
abstract SearchContext
trackScores
(boolean trackScores) abstract int
Indicates the total number of hits to count accurately.abstract SearchContext
trackTotalHitsUpTo
(int trackTotalHits) abstract boolean
version()
abstract void
version
(boolean version)
-
Field Details
-
DEFAULT_TERMINATE_AFTER
public static final int DEFAULT_TERMINATE_AFTER- See Also:
-
TRACK_TOTAL_HITS_ACCURATE
public static final int TRACK_TOTAL_HITS_ACCURATE- See Also:
-
TRACK_TOTAL_HITS_DISABLED
public static final int TRACK_TOTAL_HITS_DISABLED- See Also:
-
DEFAULT_TRACK_TOTAL_HITS_UP_TO
public static final int DEFAULT_TRACK_TOTAL_HITS_UP_TO- See Also:
-
NO_OP_BUCKET_COLLECTOR_PROCESSOR
-
-
Constructor Details
-
SearchContext
protected SearchContext()
-
-
Method Details
-
setTask
-
getTask
-
isCancelled
public abstract boolean isCancelled() -
isSearchTimedOut
public boolean isSearchTimedOut() -
setSearchTimedOut
public void setSearchTimedOut(boolean searchTimedOut) -
close
public final void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceorg.opensearch.common.lease.Releasable
-
doClose
protected abstract void doClose() -
preProcess
public abstract void preProcess(boolean rewrite) Should be called before executing the main query and after all other parameters have been set.- Parameters:
rewrite
- if the set query should be rewritten against the searcher returned fromsearcher()
-
buildFilteredQuery
public abstract org.apache.lucene.search.Query buildFilteredQuery(org.apache.lucene.search.Query query) Automatically apply all required filters to the given query such as alias filters, types filters, etc. -
id
-
source
-
request
-
searchType
-
shardTarget
-
numberOfShards
public abstract int numberOfShards() -
queryBoost
public abstract float queryBoost() -
scrollContext
-
aggregations
-
aggregations
-
addSearchExt
-
getSearchExt
-
highlight
-
highlight
-
hasInnerHits
public boolean hasInnerHits() -
innerHits
-
suggest
-
suggest
-
rescore
- Returns:
- list of all rescore contexts. empty if there aren't any.
-
addRescore
-
rescoreDocIds
-
assignRescoreDocIds
-
hasScriptFields
public abstract boolean hasScriptFields() -
scriptFields
-
sourceRequested
public abstract boolean sourceRequested()A shortcut function to see whether there is a fetchSourceContext and it says the source is requested. -
hasFetchSourceContext
public abstract boolean hasFetchSourceContext() -
fetchSourceContext
-
fetchSourceContext
-
docValuesContext
-
docValuesContext
-
fetchFieldsContext
The context related to retrieving fields. -
fetchFieldsContext
Sets the context related to retrieving fields. -
searcher
-
indexShard
-
mapperService
-
similarityService
-
bigArrays
-
bitsetFilterCache
-
timeout
public abstract org.opensearch.common.unit.TimeValue timeout() -
timeout
public abstract void timeout(org.opensearch.common.unit.TimeValue timeout) -
terminateAfter
public abstract int terminateAfter() -
terminateAfter
public abstract void terminateAfter(int terminateAfter) -
lowLevelCancellation
public abstract boolean lowLevelCancellation()Indicates if the current index should perform frequent low level search cancellation check.Enabling low-level checks will make long running searches to react to the cancellation request faster. However, since it will produce more cancellation checks it might slow the search performance down.
-
minimumScore
-
minimumScore
-
sort
-
sort
-
trackScores
-
trackScores
public abstract boolean trackScores() -
includeNamedQueriesScore
Determines whether named queries' scores should be included in the search results. By default, this is set to return false, indicating that scores from named queries are not included.- Parameters:
includeNamedQueriesScore
- true to include scores from named queries, false otherwise.
-
includeNamedQueriesScore
public boolean includeNamedQueriesScore()Checks if scores from named queries are included in the search results.- Returns:
- true if scores from named queries are included, false otherwise.
-
trackTotalHitsUpTo
-
trackTotalHitsUpTo
public abstract int trackTotalHitsUpTo()Indicates the total number of hits to count accurately. Defaults toDEFAULT_TRACK_TOTAL_HITS_UP_TO
. -
searchAfter
-
searchAfter
public abstract org.apache.lucene.search.FieldDoc searchAfter() -
collapse
-
collapse
-
parsedPostFilter
-
parsedPostFilter
-
aliasFilter
public abstract org.apache.lucene.search.Query aliasFilter() -
parsedQuery
-
parsedQuery
-
query
public abstract org.apache.lucene.search.Query query()The query to execute, might be rewritten. -
from
public abstract int from() -
from
-
size
public abstract int size() -
size
-
hasStoredFields
public abstract boolean hasStoredFields() -
hasStoredFieldsContext
public abstract boolean hasStoredFieldsContext() -
storedFieldsRequested
public abstract boolean storedFieldsRequested()A shortcut function to see whether there is a storedFieldsContext and it says the fields are requested. -
storedFieldsContext
-
storedFieldsContext
-
explain
public abstract boolean explain() -
explain
public abstract void explain(boolean explain) -
groupStats
-
groupStats
-
version
public abstract boolean version() -
version
public abstract void version(boolean version) -
seqNoAndPrimaryTerm
public abstract boolean seqNoAndPrimaryTerm()indicates whether the sequence number and primary term of the last modification to each hit should be returned -
seqNoAndPrimaryTerm
public abstract void seqNoAndPrimaryTerm(boolean seqNoAndPrimaryTerm) controls whether the sequence number and primary term of the last modification to each hit should be returned -
docIdsToLoad
public abstract int[] docIdsToLoad() -
docIdsToLoadFrom
public abstract int docIdsToLoadFrom() -
docIdsToLoadSize
public abstract int docIdsToLoadSize() -
docIdsToLoad
public abstract SearchContext docIdsToLoad(int[] docIdsToLoad, int docsIdsToLoadFrom, int docsIdsToLoadSize) -
dfsResult
-
queryResult
-
fetchPhase
-
fetchResult
-
getProfilers
Return a handle over the profilers for the current search request, ornull
if profiling is not enabled. -
shouldUseConcurrentSearch
public boolean shouldUseConcurrentSearch()Returns concurrent segment search status for the search context -
asLocalBucketCountThresholds
public LocalBucketCountThresholds asLocalBucketCountThresholds(TermsAggregator.BucketCountThresholds bucketCountThresholds) Returns local bucket count thresholds based on concurrent segment search status -
addReleasable
public void addReleasable(org.opensearch.common.lease.Releasable releasable) Adds a releasable that will be freed when this context is closed. -
hasOnlySuggest
public final boolean hasOnlySuggest()- Returns:
- true if the request contains only suggest
-
fieldType
Given the full name of a field, returns itsMappedFieldType
. -
getObjectMapper
-
getRelativeTimeInMillis
public abstract long getRelativeTimeInMillis()Returns time in milliseconds that can be used for relative time calculations. WARN: This is not the epoch time and can be a cached time. -
getRelativeTimeInMillis
public long getRelativeTimeInMillis(boolean useCache) Returns time in milliseconds that can be used for relative time calculations. this method will fall back togetRelativeTimeInMillis()
(which might be a cached time) if useCache was set to true else it will be just be a wrapper ofSystem.nanoTime()
converted to milliseconds.- Parameters:
useCache
- to allow using cached time if true or forcing callingSystem.nanoTime()
if false- Returns:
- Returns time in milliseconds that can be used for relative time calculations.
-
queryCollectorManagers
public abstract Map<Class<?>,org.apache.lucene.search.CollectorManager<? extends org.apache.lucene.search.Collector, queryCollectorManagers()ReduceableSearchResult>> Return a view of the additional query collector managers that should be run for this context. -
getQueryShardContext
-
toString
-
readerContext
-
partialOnShard
-
setBucketCollectorProcessor
-
bucketCollectorProcessor
-
shouldUseTimeSeriesDescSortOptimization
public abstract boolean shouldUseTimeSeriesDescSortOptimization() -
getTargetMaxSliceCount
public abstract int getTargetMaxSliceCount() -
maxAggRewriteFilters
public int maxAggRewriteFilters()
-