java.lang.Object
org.elasticsearch.search.internal.SearchContext
- All Implemented Interfaces:
Closeable,AutoCloseable,Releasable
- Direct Known Subclasses:
FilteredSearchContext,RankSearchContext
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intprotected final List<Releasable> static final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidIndicates that the caller will be using, and thus owning, aDfsSearchResultobject.abstract voidIndicates that the caller will be using, and thus owning, aFetchSearchResultobject.abstract voidIndicates that the caller will be using, and thus owning, aQuerySearchResultobject.abstract voidvoidaddReleasable(Releasable releasable) Adds a releasable that will be freed when this context is closed.abstract voidaddRescore(RescoreContext rescore) abstract SearchContextAggregationsabstract SearchContextaggregations(SearchContextAggregations aggregations) final voidassignRescoreDocIds(RescoreDocIds rescoreDocIds) abstract BitsetFilterCacheabstract org.apache.lucene.search.QuerybuildFilteredQuery(org.apache.lucene.search.Query query) Automatically apply all required filters to the given query such as alias filters, types filters, etc.final voidclose()abstract CollapseContextcollapse()abstract DfsSearchResultabstract FetchDocValuesContextabstract SearchContextdocValuesContext(FetchDocValuesContext docValuesContext) abstract booleanexplain()abstract voidexplain(boolean explain) abstract FetchFieldsContextThe context related to retrieving fields.abstract SearchContextfetchFieldsContext(FetchFieldsContext fetchFieldsContext) Sets the context related to retrieving fields.abstract FetchPhaseabstract FetchSearchResultabstract FetchSourceContextabstract SearchContextfetchSourceContext(FetchSourceContext fetchSourceContext) abstract intfrom()abstract SearchContextfrom(int from) abstract floatabstract ProfilersReturn a handle over the profilers for the current search request, ornullif profiling is not enabled.abstract longReturns time in milliseconds that can be used for relative time calculations.abstract SearchExecutionContextabstract SearchExtBuildergetSearchExt(String name) abstract SearchShardTaskgetTask()abstract org.apache.lucene.search.TotalHitsfinal booleanabstract booleanabstract booleanabstract SearchHighlightContextabstract voidhighlight(SearchHighlightContext highlight) abstract ShardSearchContextIdid()abstract IndexShardabstract booleanabstract booleanIndicates if the current index should perform frequent low level search cancellation check.abstract Floatabstract SearchContextminimumScore(float minimumScore) abstract IdLoaderabstract SourceLoaderBuild something to load source_source.abstract intabstract ParsedQueryabstract SearchContextparsedPostFilter(ParsedQuery postFilter) abstract ParsedQueryabstract SearchContextparsedQuery(ParsedQuery query) abstract voidShould be called before executing the main query and after all other parameters have been set.abstract org.apache.lucene.search.Queryquery()The query to execute, not rewritten.abstract QueryPhaseRankShardContextabstract voidqueryPhaseRankShardContext(QueryPhaseRankShardContext queryPhaseRankShardContext) abstract QuerySearchResultabstract RankFeatureResultabstract ReaderContextabstract ShardSearchRequestrequest()abstract List<RescoreContext> rescore()final RescoreDocIdsorg.apache.lucene.search.QueryThe query to execute in its rewritten form.abstract ScriptFieldsContextabstract ScrollContextabstract org.apache.lucene.search.FieldDocabstract SearchContextsearchAfter(org.apache.lucene.search.FieldDoc searchAfter) abstract ContextIndexSearchersearcher()abstract SearchTypeabstract booleanindicates whether the sequence number and primary term of the last modification to each hit should be returnedabstract voidseqNoAndPrimaryTerm(boolean seqNoAndPrimaryTerm) controls whether the sequence number and primary term of the last modification to each hit should be returnedabstract voidsetTask(SearchShardTask task) abstract SearchShardTargetabstract intsize()abstract SearchContextsize(int size) abstract SortAndFormatssort()abstract SearchContextsort(SortAndFormats sort) abstract Stringsource()abstract booleanA shortcut function to see whether there is a fetchSourceContext and it says the source is requested.abstract StoredFieldsContextabstract SearchContextstoredFieldsContext(StoredFieldsContext storedFieldsContext) abstract SuggestionSearchContextsuggest()abstract intabstract voidterminateAfter(int terminateAfter) abstract TimeValuetimeout()toString()abstract booleanabstract SearchContexttrackScores(boolean trackScores) abstract intIndicates the total number of hits to count accurately.abstract SearchContexttrackTotalHitsUpTo(int trackTotalHits) abstract booleanversion()abstract voidversion(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:
-
releasables
-
-
Constructor Details
-
SearchContext
protected SearchContext()
-
-
Method Details
-
getCancellationChecks
-
setTask
-
getTask
-
isCancelled
public abstract boolean isCancelled() -
close
public final void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceReleasable
-
preProcess
public abstract void preProcess()Should be called before executing the main query and after all other parameters have been set. -
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() -
scrollContext
-
aggregations
-
aggregations
-
getSearchExt
-
highlight
-
highlight
-
innerHits
-
suggest
-
queryPhaseRankShardContext
-
queryPhaseRankShardContext
public abstract void queryPhaseRankShardContext(QueryPhaseRankShardContext queryPhaseRankShardContext) -
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. -
fetchSourceContext
-
fetchSourceContext
-
docValuesContext
-
docValuesContext
-
fetchFieldsContext
The context related to retrieving fields. -
fetchFieldsContext
Sets the context related to retrieving fields. -
searcher
-
indexShard
-
bitsetFilterCache
-
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() -
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
-
parsedPostFilter
-
parsedPostFilter
-
parsedQuery
-
parsedQuery
-
query
public abstract org.apache.lucene.search.Query query()The query to execute, not rewritten. -
rewrittenQuery
public org.apache.lucene.search.Query rewrittenQuery()The query to execute in its rewritten form. -
from
public abstract int from() -
from
-
size
public abstract int size() -
size
-
hasStoredFields
public abstract boolean hasStoredFields() -
storedFieldsContext
-
storedFieldsContext
-
explain
public abstract boolean explain() -
explain
public abstract void explain(boolean explain) -
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 -
dfsResult
-
addDfsResult
public abstract void addDfsResult()Indicates that the caller will be using, and thus owning, aDfsSearchResultobject. It is the caller's responsibility to correctly cleanup this result object. -
queryResult
-
addQueryResult
public abstract void addQueryResult()Indicates that the caller will be using, and thus owning, aQuerySearchResultobject. It is the caller's responsibility to correctly cleanup this result object. -
getTotalHits
public abstract org.apache.lucene.search.TotalHits getTotalHits() -
getMaxScore
public abstract float getMaxScore() -
addRankFeatureResult
public abstract void addRankFeatureResult() -
rankFeatureResult
-
fetchPhase
-
fetchResult
-
addFetchResult
public abstract void addFetchResult()Indicates that the caller will be using, and thus owning, aFetchSearchResultobject. It is the caller's responsibility to correctly cleanup this result object. -
getProfilers
Return a handle over the profilers for the current search request, ornullif profiling is not enabled. -
addReleasable
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
-
getRelativeTimeInMillis
public abstract long getRelativeTimeInMillis()Returns time in milliseconds that can be used for relative time calculations. WARN: This is not the epoch time. -
getSearchExecutionContext
-
toString
-
readerContext
-
newSourceLoader
Build something to load source_source. -
newIdLoader
-