Class FetchPhase

java.lang.Object
org.elasticsearch.search.fetch.FetchPhase

public final class FetchPhase extends Object
Fetch phase of a search request, used to fetch the actual top matching documents to be returned to the client, identified after reducing all the matches returned by the query phase Supports both traditional mode (all results in memory) and streaming mode (results sent in chunks).
  • Constructor Details

  • Method Details

    • execute

      public void execute(SearchContext context, int[] docIdsToLoad, RankDocShardInfo rankDocs)
      Executes the fetch phase without memory checking or streaming.
      Parameters:
      context - the search context
      docIdsToLoad - document IDs to fetch
      rankDocs - ranking information
    • execute

      public void execute(SearchContext context, int[] docIdsToLoad, RankDocShardInfo rankDocs, @Nullable IntConsumer memoryChecker)
      Executes the fetch phase with an optional caller-supplied memory tracking callback and no streaming
      Parameters:
      context - the search context
      docIdsToLoad - document IDs to fetch
      rankDocs - ranking information
      memoryChecker - optional callback for memory tracking, may be null
    • execute

      public void execute(SearchContext context, int[] docIdsToLoad, RankDocShardInfo rankDocs, @Nullable IntConsumer memoryChecker, @Nullable FetchPhaseResponseChunk.Writer writer, @Nullable Integer maxInFlightChunks, @Nullable ActionListener<Void> buildListener, ActionListener<Void> listener)
      Executes the fetch phase with an optional caller-supplied memory tracking callback and optional streaming.

      When writer is null (non-streaming), all hits are accumulated in memory and returned at once. When writer is provided (streaming), hits are emitted in chunks to reduce peak memory usage. In streaming mode, the final completion may be delayed by transport-level acknowledgements, but the fetch build completion is signaled as soon as the fetch work has finished.

      Parameters:
      context - the search context
      docIdsToLoad - document IDs to fetch
      rankDocs - ranking information
      memoryChecker - optional callback for memory tracking, may be null
      writer - optional chunk writer for streaming mode, may be null
      buildListener - optional listener invoked when all SearchHit objects have been constructed (and, in streaming mode, serialized into chunks and dispatched to the writer). In non-streaming mode this fires immediately after the hits are built, just like listener. In streaming mode this fires before chunk ACKs arrive, allowing the caller to release shard resources (e.g. close the SearchContext) without waiting for network acknowledgements.
      listener - final completion listener. In streaming mode this is invoked only after all chunks are ACKed; in non-streaming mode it is invoked immediately after hits are built.
      Throws:
      TaskCancelledException - if the task is cancelled