Class SearchContext

java.lang.Object
org.elasticsearch.search.internal.SearchContext
All Implemented Interfaces:
Closeable, AutoCloseable, Releasable
Direct Known Subclasses:
FilteredSearchContext, RankSearchContext

public abstract class SearchContext extends 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 Details

  • Constructor Details

    • SearchContext

      protected SearchContext()
  • Method Details

    • getCancellationChecks

      public final List<Runnable> getCancellationChecks()
    • setTask

      public abstract void setTask(CancellableTask task)
    • getTask

      public abstract CancellableTask getTask()
    • isCancelled

      public abstract boolean isCancelled()
    • close

      public final void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Releasable
    • isClosed

      public final boolean isClosed()
    • 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

      public abstract ShardSearchContextId id()
    • source

      public abstract String source()
    • request

      public abstract ShardSearchRequest request()
    • searchType

      public abstract SearchType searchType()
    • shardTarget

      public abstract SearchShardTarget shardTarget()
    • numberOfShards

      public abstract int numberOfShards()
    • scrollContext

      public abstract ScrollContext scrollContext()
    • aggregations

      public abstract SearchContextAggregations aggregations()
    • aggregations

      public abstract SearchContext aggregations(SearchContextAggregations aggregations)
    • getSearchExt

      public abstract SearchExtBuilder getSearchExt(String name)
    • highlight

      public abstract SearchHighlightContext highlight()
    • highlight

      public abstract void highlight(SearchHighlightContext highlight)
    • innerHits

      public InnerHitsContext innerHits()
    • suggest

      public abstract SuggestionSearchContext suggest()
    • queryPhaseRankShardContext

      public abstract QueryPhaseRankShardContext queryPhaseRankShardContext()
    • queryPhaseRankShardContext

      public abstract void queryPhaseRankShardContext(QueryPhaseRankShardContext queryPhaseRankShardContext)
    • rescore

      public abstract List<RescoreContext> rescore()
      Returns:
      list of all rescore contexts. empty if there aren't any.
    • addRescore

      public abstract void addRescore(RescoreContext rescore)
    • rescoreDocIds

      public final RescoreDocIds rescoreDocIds()
    • assignRescoreDocIds

      public final void assignRescoreDocIds(RescoreDocIds rescoreDocIds)
    • hasScriptFields

      public abstract boolean hasScriptFields()
    • scriptFields

      public abstract ScriptFieldsContext scriptFields()
    • sourceRequested

      public abstract boolean sourceRequested()
      A shortcut function to see whether there is a fetchSourceContext and it says the source is requested.
    • fetchSourceContext

      public abstract FetchSourceContext fetchSourceContext()
    • fetchSourceContext

      public abstract SearchContext fetchSourceContext(FetchSourceContext fetchSourceContext)
    • docValuesContext

      public abstract FetchDocValuesContext docValuesContext()
    • docValuesContext

      public abstract SearchContext docValuesContext(FetchDocValuesContext docValuesContext)
    • fetchFieldsContext

      public abstract FetchFieldsContext fetchFieldsContext()
      The context related to retrieving fields.
    • fetchFieldsContext

      public abstract SearchContext fetchFieldsContext(FetchFieldsContext fetchFieldsContext)
      Sets the context related to retrieving fields.
    • searcher

      public abstract ContextIndexSearcher searcher()
    • indexShard

      public abstract IndexShard indexShard()
    • bitsetFilterCache

      public abstract BitsetFilterCache bitsetFilterCache()
    • timeout

      public abstract 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

      public abstract SearchContext minimumScore(float minimumScore)
    • minimumScore

      public abstract Float minimumScore()
    • sort

      public abstract SearchContext sort(SortAndFormats sort)
    • sort

      public abstract SortAndFormats sort()
    • trackScores

      public abstract SearchContext trackScores(boolean trackScores)
    • trackScores

      public abstract boolean trackScores()
    • trackTotalHitsUpTo

      public abstract SearchContext trackTotalHitsUpTo(int trackTotalHits)
    • trackTotalHitsUpTo

      public abstract int trackTotalHitsUpTo()
      Indicates the total number of hits to count accurately. Defaults to DEFAULT_TRACK_TOTAL_HITS_UP_TO.
    • searchAfter

      public abstract SearchContext searchAfter(org.apache.lucene.search.FieldDoc searchAfter)
    • searchAfter

      public abstract org.apache.lucene.search.FieldDoc searchAfter()
    • collapse

      public abstract CollapseContext collapse()
    • parsedPostFilter

      public abstract SearchContext parsedPostFilter(ParsedQuery postFilter)
    • parsedPostFilter

      public abstract ParsedQuery parsedPostFilter()
    • parsedQuery

      public abstract SearchContext parsedQuery(ParsedQuery query)
    • parsedQuery

      public abstract 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

      public abstract SearchContext from(int from)
    • size

      public abstract int size()
    • size

      public abstract SearchContext size(int size)
    • hasStoredFields

      public abstract boolean hasStoredFields()
    • storedFieldsContext

      public abstract StoredFieldsContext storedFieldsContext()
    • storedFieldsContext

      public abstract SearchContext storedFieldsContext(StoredFieldsContext storedFieldsContext)
    • explain

      public abstract boolean explain()
    • explain

      public abstract void explain(boolean explain)
    • groupStats

      @Nullable public abstract List<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
    • dfsResult

      public abstract DfsSearchResult dfsResult()
    • addDfsResult

      public abstract void addDfsResult()
      Indicates that the caller will be using, and thus owning, a DfsSearchResult object. It is the caller's responsibility to correctly cleanup this result object.
    • queryResult

      public abstract QuerySearchResult queryResult()
    • addQueryResult

      public abstract void addQueryResult()
      Indicates that the caller will be using, and thus owning, a QuerySearchResult object. 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

      public abstract RankFeatureResult rankFeatureResult()
    • fetchPhase

      public abstract FetchPhase fetchPhase()
    • fetchResult

      public abstract FetchSearchResult fetchResult()
    • addFetchResult

      public abstract void addFetchResult()
      Indicates that the caller will be using, and thus owning, a FetchSearchResult object. It is the caller's responsibility to correctly cleanup this result object.
    • getProfilers

      public abstract Profilers getProfilers()
      Return a handle over the profilers for the current search request, or null if profiling is not enabled.
    • circuitBreaker

      public abstract CircuitBreaker circuitBreaker()
      The circuit breaker used to account for the search operation.
    • memAccountingBufferSize

      public abstract long memAccountingBufferSize()
      Return the amount of memory to buffer locally before accounting for it in the breaker.
    • checkRealMemoryCB

      public final boolean checkRealMemoryCB(int locallyAccumulatedBytes, String label)
      Checks if the accumulated bytes are greater than the buffer size and if so, checks the available memory in the parent breaker (the real memory breaker).
      Parameters:
      locallyAccumulatedBytes - the number of bytes accumulated locally
      label - the label to use in the breaker
      Returns:
      true if the real memory breaker is called and false otherwise
    • addReleasable

      public void addReleasable(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
    • 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

      public abstract SearchExecutionContext getSearchExecutionContext()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • readerContext

      public abstract ReaderContext readerContext()
    • newSourceLoader

      public abstract SourceLoader newSourceLoader(@Nullable SourceFilter sourceFilter)
      Build something to load source _source.
    • newIdLoader

      public abstract IdLoader newIdLoader()