Class SearchHit

All Implemented Interfaces:
Iterable<DocumentField>, Writeable, ToXContent, ToXContentObject

public final class SearchHit extends Object implements Writeable, ToXContentObject, Iterable<DocumentField>
A single search hit.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • writeTo

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

      public int docId()
    • score

      public void score(float score)
    • getScore

      public float getScore()
      The score.
    • version

      public void version(long version)
    • getVersion

      public long getVersion()
      The version of the hit.
    • setSeqNo

      public void setSeqNo(long seqNo)
    • setPrimaryTerm

      public void setPrimaryTerm(long primaryTerm)
    • getSeqNo

      public long getSeqNo()
      returns the sequence number of the last modification to the document, or SequenceNumbers.UNASSIGNED_SEQ_NO if not requested.
    • getPrimaryTerm

      public long getPrimaryTerm()
      returns the primary term of the last modification to the document, or SequenceNumbers.UNASSIGNED_PRIMARY_TERM if not requested.
    • getIndex

      public String getIndex()
      The index of the hit.
    • getId

      public String getId()
      The id of the document.
    • getType

      @Deprecated public String getType()
      Types are in the process of being removed. Instead of using a type, prefer to filter on a field on the document.
      The type of the document.
    • getNestedIdentity

      public SearchHit.NestedIdentity getNestedIdentity()
      If this is a nested hit then nested reference information is returned otherwise null is returned.
    • getSourceRef

      public BytesReference getSourceRef()
      Returns bytes reference, also uncompress the source if needed.
    • sourceRef

      public SearchHit sourceRef(BytesReference source)
      Sets representation, might be compressed....
    • hasSource

      public boolean hasSource()
      Is the source available or not. A source with no fields will return true. This will return false if fields doesn't contain _source or if source is disabled in the mapping.
    • getSourceAsString

      public String getSourceAsString()
      The source of the document as string (can be null).
    • getSourceAsMap

      public Map<String,Object> getSourceAsMap()
      The source of the document as a map (can be null).
    • iterator

      public Iterator<DocumentField> iterator()
      Specified by:
      iterator in interface Iterable<DocumentField>
    • field

      public DocumentField field(String fieldName)
      The hit field matching the given field name.
    • setDocumentField

      public void setDocumentField(String fieldName, DocumentField field)
    • getMetadataFields

      public Map<String,DocumentField> getMetadataFields()
      a map of metadata fields for this hit
    • getDocumentFields

      public Map<String,DocumentField> getDocumentFields()
      a map of non-metadata fields requested for this hit
    • getFields

      public Map<String,DocumentField> getFields()
      A map of hit fields (from field name to hit fields) if additional fields were required to be loaded. Includes both document and metadata fields.
    • getHighlightFields

      public Map<String,HighlightField> getHighlightFields()
      A map of highlighted fields.
    • highlightFields

      public void highlightFields(Map<String,HighlightField> highlightFields)
    • sortValues

      public void sortValues(Object[] sortValues, DocValueFormat[] sortValueFormats)
    • sortValues

      public void sortValues(SearchSortValues sortValues)
    • getSortValues

      public Object[] getSortValues()
      An array of the (formatted) sort values used.
    • getRawSortValues

      public Object[] getRawSortValues()
      An array of the (raw) sort values used.
    • getExplanation

      public getExplanation()
      If enabled, the explanation of the search hit.
    • explanation

      public void explanation( explanation)
    • getShard

      public SearchShardTarget getShard()
      The shard of the search hit.
    • shard

      public void shard(SearchShardTarget target)
    • getClusterAlias

      public String getClusterAlias()
      Returns the cluster alias this hit comes from or null if it comes from a local cluster
    • matchedQueries

      public void matchedQueries(String[] matchedQueries)
    • getMatchedQueries

      public String[] getMatchedQueries()
      The set of query and filter names the query matched with. Mainly makes sense for compound filters and queries.
    • getInnerHits

      public Map<String,SearchHits> getInnerHits()
      Inner hits or null if there are none
    • setInnerHits

      public void setInnerHits(Map<String,SearchHits> innerHits)
    • toXContent

      public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
      Specified by:
      toXContent in interface ToXContent
    • toInnerXContent

      public XContentBuilder toInnerXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
    • fromXContent

      public static SearchHit fromXContent(XContentParser parser)
    • declareInnerHitsParseFields

      public static void declareInnerHitsParseFields(ObjectParser<Map<String,Object>,Void> parser)
    • createFromMap

      public static SearchHit createFromMap(Map<String,Object> values)
    • equals

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

      public int hashCode()
      hashCode in class Object
    • toString

      public String toString()
      toString in class Object