Class SearchContext
java.lang.Object
org.elasticsearch.search.internal.SearchContext
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Releasable
- Direct Known Subclasses:
FilteredSearchContext
public abstract class SearchContext extends java.lang.Object implements 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.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_TERMINATE_AFTERstatic intDEFAULT_TRACK_TOTAL_HITS_UP_TOstatic intTRACK_TOTAL_HITS_ACCURATEstatic intTRACK_TOTAL_HITS_DISABLED -
Constructor Summary
Constructors Modifier Constructor Description protectedSearchContext() -
Method Summary
Modifier and Type Method Description voidaddReleasable(Releasable releasable)Adds a releasable that will be freed when this context is closed.abstract voidaddRescore(RescoreContext rescore)abstract voidaddSearchExt(SearchExtBuilder searchExtBuilder)abstract SearchContextAggregationsaggregations()abstract SearchContextaggregations(SearchContextAggregations aggregations)abstract org.apache.lucene.search.QueryaliasFilter()voidassignRescoreDocIds(RescoreDocIds rescoreDocIds)abstract BigArraysbigArrays()abstract BitsetFilterCachebitsetFilterCache()abstract 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.voidclose()abstract CollapseContextcollapse()abstract SearchContextcollapse(CollapseContext collapse)abstract DfsSearchResultdfsResult()abstract int[]docIdsToLoad()abstract SearchContextdocIdsToLoad(int[] docIdsToLoad, int docsIdsToLoadFrom, int docsIdsToLoadSize)abstract intdocIdsToLoadFrom()abstract intdocIdsToLoadSize()protected abstract voiddoClose()abstract FetchDocValuesContextdocValuesContext()abstract SearchContextdocValuesContext(FetchDocValuesContext docValuesContext)abstract booleanexplain()abstract voidexplain(boolean explain)abstract FetchFieldsContextfetchFieldsContext()The context related to retrieving fields.abstract SearchContextfetchFieldsContext(FetchFieldsContext fetchFieldsContext)Sets the context related to retrieving fields.abstract FetchPhasefetchPhase()abstract FetchSearchResultfetchResult()abstract FetchSourceContextfetchSourceContext()abstract SearchContextfetchSourceContext(FetchSourceContext fetchSourceContext)abstract MappedFieldTypefieldType(java.lang.String name)Given the full name of a field, returns itsMappedFieldType.abstract intfrom()abstract SearchContextfrom(int from)abstract ObjectMappergetObjectMapper(java.lang.String name)abstract ProfilersgetProfilers()Return a handle over the profilers for the current search request, ornullif profiling is not enabled.abstract QueryShardContextgetQueryShardContext()abstract longgetRelativeTimeInMillis()Returns time in milliseconds that can be used for relative time calculations.abstract SearchExtBuildergetSearchExt(java.lang.String name)abstract SearchShardTaskgetTask()abstract java.util.List<java.lang.String>groupStats()abstract voidgroupStats(java.util.List<java.lang.String> groupStats)abstract booleanhasFetchSourceContext()booleanhasOnlySuggest()abstract booleanhasScriptFields()abstract booleanhasStoredFields()abstract booleanhasStoredFieldsContext()abstract SearchHighlightContexthighlight()abstract voidhighlight(SearchHighlightContext highlight)abstract ShardSearchContextIdid()abstract IndexShardindexShard()InnerHitsContextinnerHits()abstract booleanisCancelled()abstract booleanlowLevelCancellation()Indicates if the current index should perform frequent low level search cancellation check.abstract MapperServicemapperService()abstract java.lang.FloatminimumScore()abstract SearchContextminimumScore(float minimumScore)abstract intnumberOfShards()abstract ParsedQueryparsedPostFilter()abstract SearchContextparsedPostFilter(ParsedQuery postFilter)abstract ParsedQueryparsedQuery()abstract SearchContextparsedQuery(ParsedQuery query)abstract voidpreProcess(boolean rewrite)Should 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, might be rewritten.abstract floatqueryBoost()abstract java.util.Map<java.lang.Class<?>,org.apache.lucene.search.Collector>queryCollectors()Return a view of the additional query collectors that should be run for this context.abstract QuerySearchResultqueryResult()abstract ReaderContextreaderContext()abstract ShardSearchRequestrequest()abstract java.util.List<RescoreContext>rescore()RescoreDocIdsrescoreDocIds()abstract ScriptFieldsContextscriptFields()abstract ScrollContextscrollContext()abstract org.apache.lucene.search.FieldDocsearchAfter()abstract SearchContextsearchAfter(org.apache.lucene.search.FieldDoc searchAfter)abstract ContextIndexSearchersearcher()abstract SearchTypesearchType()abstract booleanseqNoAndPrimaryTerm()indicates 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 SearchShardTargetshardTarget()abstract SimilarityServicesimilarityService()abstract intsize()abstract SearchContextsize(int size)abstract SortAndFormatssort()abstract SearchContextsort(SortAndFormats sort)abstract java.lang.Stringsource()abstract booleansourceRequested()A shortcut function to see whether there is a fetchSourceContext and it says the source is requested.abstract StoredFieldsContextstoredFieldsContext()abstract SearchContextstoredFieldsContext(StoredFieldsContext storedFieldsContext)abstract booleanstoredFieldsRequested()A shortcut function to see whether there is a storedFieldsContext and it says the fields are requested.abstract SuggestionSearchContextsuggest()abstract voidsuggest(SuggestionSearchContext suggest)abstract intterminateAfter()abstract voidterminateAfter(int terminateAfter)abstract org.elasticsearch.common.unit.TimeValuetimeout()abstract voidtimeout(org.elasticsearch.common.unit.TimeValue timeout)java.lang.StringtoString()abstract booleantrackScores()abstract SearchContexttrackScores(boolean trackScores)abstract inttrackTotalHitsUpTo()Indicates 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:
- Constant Field Values
-
TRACK_TOTAL_HITS_ACCURATE
public static final int TRACK_TOTAL_HITS_ACCURATE- See Also:
- Constant Field Values
-
TRACK_TOTAL_HITS_DISABLED
public static final int TRACK_TOTAL_HITS_DISABLED- See Also:
- Constant Field Values
-
DEFAULT_TRACK_TOTAL_HITS_UP_TO
public static final int DEFAULT_TRACK_TOTAL_HITS_UP_TO- See Also:
- Constant Field Values
-
-
Constructor Details
-
SearchContext
protected SearchContext()
-
-
Method Details
-
setTask
-
getTask
-
isCancelled
public abstract boolean isCancelled() -
close
public final void close()- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceReleasable
-
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
public abstract java.lang.String source() -
request
-
searchType
-
shardTarget
-
numberOfShards
public abstract int numberOfShards() -
queryBoost
public abstract float queryBoost() -
scrollContext
-
aggregations
-
aggregations
-
addSearchExt
-
getSearchExt
-
highlight
-
highlight
-
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.elasticsearch.common.unit.TimeValue timeout() -
timeout
public abstract void timeout(org.elasticsearch.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
public abstract java.lang.Float 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
-
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
@Nullable public abstract java.util.List<java.lang.String> groupStats() -
groupStats
public abstract void groupStats(java.util.List<java.lang.String> 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, 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
-
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. -
queryCollectors
public abstract java.util.Map<java.lang.Class<?>,org.apache.lucene.search.Collector> queryCollectors()Return a view of the additional query collectors that should be run for this context. -
getQueryShardContext
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
readerContext
-