Class QuerySearchResult

All Implemented Interfaces:
Writeable, RefCounted

public final class QuerySearchResult extends SearchPhaseResult
  • Constructor Details

    • QuerySearchResult

      public QuerySearchResult()
    • QuerySearchResult

      public QuerySearchResult(StreamInput in) throws IOException
      Throws:
      IOException
    • QuerySearchResult

      public QuerySearchResult(StreamInput in, boolean delayedAggregations) throws IOException
      Read the object, but using a delayed aggregations field when delayedAggregations=true. Using this, the caller must ensure that either `consumeAggs` or `releaseAggs` is called if `hasAggs() == true`.
      Parameters:
      delayedAggregations - whether to use delayed aggregations or not
      Throws:
      IOException
    • QuerySearchResult

      public QuerySearchResult(ShardSearchContextId contextId, SearchShardTarget shardTarget, ShardSearchRequest shardSearchRequest)
  • Method Details

    • nullInstance

      public static QuerySearchResult nullInstance()
      Returns an instance that contains no response.
    • isNull

      public boolean isNull()
      Returns true if the result doesn't contain any useful information. It is used by the search action to avoid creating an empty response on shard request that rewrites to match_no_docs. TODO: Currently we need the concrete aggregators to build empty responses. This means that we cannot build an empty response in the coordinating node so we rely on this hack to ensure that at least one shard returns a valid empty response. We should move the ability to create empty responses to aggregation builders in order to allow building empty responses directly from the coordinating node.
    • queryResult

      public QuerySearchResult queryResult()
      Description copied from class: SearchPhaseResult
      Returns the query result iff it's included in this response otherwise null
      Overrides:
      queryResult in class SearchPhaseResult
    • searchTimedOut

      public void searchTimedOut(boolean searchTimedOut)
    • searchTimedOut

      public boolean searchTimedOut()
    • terminatedEarly

      public void terminatedEarly(boolean terminatedEarly)
    • terminatedEarly

      @Nullable public Boolean terminatedEarly()
    • topDocs

      public TopDocsAndMaxScore topDocs()
    • hasConsumedTopDocs

      public boolean hasConsumedTopDocs()
      Returns true iff the top docs have already been consumed.
    • consumeTopDocs

      public TopDocsAndMaxScore consumeTopDocs()
      Returns and nulls out the top docs for this search results. This allows to free up memory once the top docs are consumed.
      Throws:
      IllegalStateException - if the top docs have already been consumed.
    • topDocs

      public void topDocs(TopDocsAndMaxScore topDocs, DocValueFormat[] sortValueFormats)
    • setRankShardResult

      public void setRankShardResult(RankShardResult rankShardResult)
    • getRankShardResult

      @Nullable public RankShardResult getRankShardResult()
    • sortValueFormats

      @Nullable public DocValueFormat[] sortValueFormats()
    • hasAggs

      public boolean hasAggs()
      Returns true if this query result has unconsumed aggregations
    • getAggs

      Returns the aggregation as a DelayableWriteable object. Callers are free to expand them whenever they wat but they should call releaseAggs() in order to free memory,
      Throws:
      IllegalStateException - if releaseAggs() has already being called.
    • releaseAggs

      public void releaseAggs()
      Release the memory hold by the DelayableWriteable aggregations
      Throws:
      IllegalStateException - if releaseAggs() has already being called.
    • addReleasable

      public void addReleasable(Releasable releasable)
    • aggregations

      public void aggregations(InternalAggregations aggregations)
    • aggregations

    • setSearchProfileDfsPhaseResult

      public void setSearchProfileDfsPhaseResult(SearchProfileDfsPhaseResult searchProfileDfsPhaseResult)
    • consumeProfileResult

      public SearchProfileQueryPhaseResult consumeProfileResult()
      Returns and nulls out the profiled results for this search, or potentially null if result was empty. This allows to free up memory once the profiled result is consumed.
      Throws:
      IllegalStateException - if the profiled result has already been consumed.
    • hasProfileResults

      public boolean hasProfileResults()
    • consumeAll

      public void consumeAll()
    • profileResults

      public void profileResults(SearchProfileQueryPhaseResult shardResults)
      Sets the finalized profiling results for this query
      Parameters:
      shardResults - The finalized profile
    • suggest

      public Suggest suggest()
    • suggest

      public void suggest(Suggest suggest)
    • from

      public int from()
    • from

      public QuerySearchResult from(int from)
    • size

      public int size()
      Returns the maximum size of this results top docs.
    • size

      public QuerySearchResult size(int size)
    • serviceTimeEWMA

      public long serviceTimeEWMA()
    • serviceTimeEWMA

      public QuerySearchResult serviceTimeEWMA(long serviceTimeEWMA)
    • nodeQueueSize

      public int nodeQueueSize()
    • nodeQueueSize

      public QuerySearchResult nodeQueueSize(int nodeQueueSize)
    • hasSuggestHits

      public boolean hasSuggestHits()
      Returns true if this result has any suggest score docs
    • hasSearchContext

      public boolean hasSearchContext()
    • readFromWithId

      public void readFromWithId(ShardSearchContextId id, StreamInput in) throws IOException
      Throws:
      IOException
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Overrides:
      writeTo in class SearchPhaseResult
      Throws:
      IOException
    • writeToNoId

      public void writeToNoId(StreamOutput out) throws IOException
      Throws:
      IOException
    • getTotalHits

      @Nullable public org.apache.lucene.search.TotalHits getTotalHits()
    • getMaxScore

      public float getMaxScore()
    • incRef

      public void incRef()
      Specified by:
      incRef in interface RefCounted
      Overrides:
      incRef in class TransportMessage
    • tryIncRef

      public boolean tryIncRef()
      Specified by:
      tryIncRef in interface RefCounted
      Overrides:
      tryIncRef in class TransportMessage
    • decRef

      public boolean decRef()
      Description copied from class: TransportMessage
      Note that the lifetime of an outbound TransportMessage lasts at least until it has been fully sent over the network, and it may be closed on a network thread in a context in which there's a risk of stack overflows if on close it calls back into the network layer in a manner that might end up nesting too deeply. When in doubt, dispatch any further work onto a separate thread.
      Specified by:
      decRef in interface RefCounted
      Overrides:
      decRef in class TransportMessage
    • hasReferences

      public boolean hasReferences()
      Specified by:
      hasReferences in interface RefCounted
      Overrides:
      hasReferences in class TransportMessage