Class SearchHits

java.lang.Object
org.elasticsearch.search.SearchHits
All Implemented Interfaces:
Iterable<SearchHit>, Writeable, ChunkedToXContent, RefCounted

public final class SearchHits extends Object implements Writeable, ChunkedToXContent, RefCounted, Iterable<SearchHit>
  • Field Details

    • EMPTY

      public static final SearchHit[] EMPTY
    • EMPTY_WITH_TOTAL_HITS

      public static final SearchHits EMPTY_WITH_TOTAL_HITS
    • EMPTY_WITHOUT_TOTAL_HITS

      public static final SearchHits EMPTY_WITHOUT_TOTAL_HITS
  • Constructor Details

    • SearchHits

      public SearchHits(SearchHit[] hits, @Nullable org.apache.lucene.search.TotalHits totalHits, float maxScore)
    • SearchHits

      public SearchHits(SearchHit[] hits, @Nullable org.apache.lucene.search.TotalHits totalHits, float maxScore, @Nullable org.apache.lucene.search.SortField[] sortFields, @Nullable String collapseField, @Nullable Object[] collapseValues)
  • Method Details

    • empty

      public static SearchHits empty(@Nullable org.apache.lucene.search.TotalHits totalHits, float maxScore)
    • unpooled

      public static SearchHits unpooled(SearchHit[] hits, @Nullable org.apache.lucene.search.TotalHits totalHits, float maxScore)
    • unpooled

      public static SearchHits unpooled(SearchHit[] hits, @Nullable org.apache.lucene.search.TotalHits totalHits, float maxScore, @Nullable org.apache.lucene.search.SortField[] sortFields, @Nullable String collapseField, @Nullable Object[] collapseValues)
    • readFrom

      public static SearchHits readFrom(StreamInput in, boolean pooled) 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
      Throws:
      IOException
    • getTotalHits

      @Nullable public org.apache.lucene.search.TotalHits getTotalHits()
      The total number of hits for the query or null if the tracking of total hits is disabled in the request.
    • getMaxScore

      public float getMaxScore()
      The maximum score of this query.
    • getHits

      public SearchHit[] getHits()
      The hits of the search request (based on the search type, and from / size provided).
    • getAt

      public SearchHit getAt(int position)
      Return the hit as the provided position.
    • getSortFields

      @Nullable public org.apache.lucene.search.SortField[] getSortFields()
      In case documents were sorted by field(s), returns information about such field(s), null otherwise
      See Also:
      • SortField
    • getCollapseField

      @Nullable public String getCollapseField()
      In case field collapsing was performed, returns the field used for field collapsing, null otherwise
    • getCollapseValues

      @Nullable public Object[] getCollapseValues()
      In case field collapsing was performed, returns the values of the field that field collapsing was performed on, null otherwise
    • iterator

      public Iterator<SearchHit> iterator()
      Specified by:
      iterator in interface Iterable<SearchHit>
    • incRef

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

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

      public boolean decRef()
      Specified by:
      decRef in interface RefCounted
    • hasReferences

      public boolean hasReferences()
      Specified by:
      hasReferences in interface RefCounted
    • asUnpooled

      public SearchHits asUnpooled()
    • toXContentChunked

      public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params)
      Description copied from interface: ChunkedToXContent
      Create an iterator of ToXContent chunks for a REST response. Each chunk is serialized with the same XContentBuilder and ToXContent.Params, which is also the same as the ToXContent.Params passed as the params argument. For best results, all chunks should be O(1) size. The last chunk in the iterator must always yield at least one byte of output. See also ChunkedToXContentHelper for some handy utilities.

      Note that chunked response bodies cannot send deprecation warning headers once transmission has started, so implementations must check for deprecated feature use before returning.

      Specified by:
      toXContentChunked in interface ChunkedToXContent
      Returns:
      iterator over chunks of ToXContent
    • fromXContent

      public static SearchHits fromXContent(XContentParser parser) throws IOException
      Throws:
      IOException
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • parseTotalHitsFragment

      public static org.apache.lucene.search.TotalHits parseTotalHitsFragment(XContentParser parser) throws IOException
      Throws:
      IOException