Class SearchContext

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, Releasable, RefCounted
    Direct Known Subclasses:
    FilteredSearchContext

    public abstract class SearchContext
    extends AbstractRefCounted
    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. This class also implements RefCounted since in some situations like in SearchService a SearchContext can be closed concurrently due to independent events ie. when an index gets removed. To prevent accessing closed IndexReader / IndexSearcher instances the SearchContext can be guarded by a reference count and fail if it's been closed by an external event.
    • Field Detail

      • DEFAULT_TERMINATE_AFTER

        public static final int DEFAULT_TERMINATE_AFTER
        See Also:
        Constant Field Values
    • Constructor Detail

      • SearchContext

        protected SearchContext()
    • Method Detail

      • setTask

        public abstract void setTask​(SearchTask task)
      • isCancelled

        public abstract boolean isCancelled()
      • close

        public final void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface 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 from searcher()
      • 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 long id()
      • source

        public abstract java.lang.String source()
      • searchType

        public abstract SearchType searchType()
      • numberOfShards

        public abstract int numberOfShards()
      • queryBoost

        public abstract float queryBoost()
      • getOriginNanoTime

        public abstract long getOriginNanoTime()
      • addSearchExt

        public abstract void addSearchExt​(SearchExtBuilder searchExtBuilder)
      • getSearchExt

        public abstract SearchExtBuilder getSearchExt​(java.lang.String name)
      • rescore

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

        public abstract void addRescore​(RescoreContext rescore)
      • hasScriptFields

        public abstract boolean hasScriptFields()
      • 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()
      • indexShard

        public abstract IndexShard indexShard()
      • bigArrays

        public abstract BigArrays bigArrays()
      • timeout

        public abstract TimeValue timeout()
      • timeout

        public abstract void timeout​(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 java.lang.Float minimumScore()
      • trackScores

        public abstract SearchContext trackScores​(boolean trackScores)
      • trackScores

        public abstract boolean trackScores()
      • trackTotalHits

        public abstract SearchContext trackTotalHits​(boolean trackTotalHits)
      • trackTotalHits

        public abstract boolean trackTotalHits()
        Indicates if the total hit count for the query should be tracked. Defaults to true
      • searchAfter

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

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

        public abstract ParsedQuery parsedPostFilter()
      • aliasFilter

        public abstract org.apache.lucene.search.Query aliasFilter()
      • parsedQuery

        public abstract ParsedQuery parsedQuery()
      • query

        public abstract org.apache.lucene.search.Query query()
        The query to execute, might be rewritten.
      • from

        public abstract int from()
      • size

        public abstract int 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.
      • 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)
      • 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)
      • accessed

        public abstract void accessed​(long accessTime)
      • lastAccessTime

        public abstract long lastAccessTime()
      • keepAlive

        public abstract long keepAlive()
      • keepAlive

        public abstract void keepAlive​(long keepAlive)
      • fetchPhase

        public abstract FetchPhase fetchPhase()
      • getProfilers

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

        public final boolean hasOnlySuggest()
        Returns:
        true if the request contains only suggest
      • smartNameFieldType

        public abstract MappedFieldType smartNameFieldType​(java.lang.String name)
        Looks up the given field, but does not restrict to fields in the types set on this context.
      • getObjectMapper

        public abstract ObjectMapper getObjectMapper​(java.lang.String name)
      • timeEstimateCounter

        public abstract org.apache.lucene.util.Counter timeEstimateCounter()
      • 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.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object