Package org.elasticsearch.search
Class SearchHit
- java.lang.Object
-
- org.elasticsearch.search.SearchHit
-
- All Implemented Interfaces:
java.lang.Iterable<DocumentField>,Streamable,ToXContent,ToXContentObject
public final class SearchHit extends java.lang.Object implements Streamable, ToXContentObject, java.lang.Iterable<DocumentField>
A single search hit.- See Also:
SearchHits
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSearchHit.Fieldsstatic classSearchHit.NestedIdentityEncapsulates the nested identity of a hit.-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
-
Field Summary
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description SearchHit(int docId)SearchHit(int docId, java.lang.String id, Text type, java.util.Map<java.lang.String,DocumentField> fields)SearchHit(int nestedTopDocId, java.lang.String id, Text type, SearchHit.NestedIdentity nestedIdentity, java.util.Map<java.lang.String,DocumentField> fields)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SearchHitcreateFromMap(java.util.Map<java.lang.String,java.lang.Object> values)static voiddeclareInnerHitsParseFields(ObjectParser<java.util.Map<java.lang.String,java.lang.Object>,java.lang.Void> parser)intdocId()booleanequals(java.lang.Object obj)voidexplanation(org.apache.lucene.search.Explanation explanation)DocumentFieldfield(java.lang.String fieldName)The hit field matching the given field name.voidfields(java.util.Map<java.lang.String,DocumentField> fields)java.util.Map<java.lang.String,DocumentField>fieldsOrNull()static SearchHitfromXContent(XContentParser parser)java.lang.StringgetClusterAlias()Returns the cluster alias this hit comes from or null if it comes from a local clusterorg.apache.lucene.search.ExplanationgetExplanation()If enabled, the explanation of the search hit.java.util.Map<java.lang.String,DocumentField>getFields()A map of hit fields (from field name to hit fields) if additional fields were required to be loaded.java.util.Map<java.lang.String,HighlightField>getHighlightFields()A map of highlighted fields.java.lang.StringgetId()The id of the document.java.lang.StringgetIndex()The index of the hit.java.util.Map<java.lang.String,SearchHits>getInnerHits()java.lang.String[]getMatchedQueries()The set of query and filter names the query matched with.SearchHit.NestedIdentitygetNestedIdentity()If this is a nested hit then nested reference information is returned otherwisenullis returned.floatgetScore()The score.SearchShardTargetgetShard()The shard of the search hit.java.lang.Object[]getSortValues()An array of the sort values used.java.util.Map<java.lang.String,java.lang.Object>getSourceAsMap()The source of the document as a map (can benull).java.lang.StringgetSourceAsString()The source of the document as string (can benull).BytesReferencegetSourceRef()Returns bytes reference, also uncompress the source if needed.java.lang.StringgetType()The type of the document.longgetVersion()The version of the hit.inthashCode()booleanhasSource()Is the source available or not.voidhighlightFields(java.util.Map<java.lang.String,HighlightField> highlightFields)java.util.Iterator<DocumentField>iterator()voidmatchedQueries(java.lang.String[] matchedQueries)voidreadFrom(StreamInput in)Set this object's fields from a StreamInput.static SearchHitreadSearchHit(StreamInput in)voidscore(float score)voidsetInnerHits(java.util.Map<java.lang.String,SearchHits> innerHits)voidshard(SearchShardTarget target)voidsortValues(java.lang.Object[] sortValues, DocValueFormat[] sortValueFormats)voidsortValues(SearchSortValues sortValues)SearchHitsourceRef(BytesReference source)Sets representation, might be compressed....XContentBuildertoInnerXContent(XContentBuilder builder, ToXContent.Params params)java.lang.StringtoString()XContentBuildertoXContent(XContentBuilder builder, ToXContent.Params params)voidversion(long version)voidwriteTo(StreamOutput out)Write this object's fields to a StreamOutput.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.io.stream.Streamable
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Constructor Detail
-
SearchHit
public SearchHit(int docId)
-
SearchHit
public SearchHit(int docId, java.lang.String id, Text type, java.util.Map<java.lang.String,DocumentField> fields)
-
SearchHit
public SearchHit(int nestedTopDocId, java.lang.String id, Text type, SearchHit.NestedIdentity nestedIdentity, java.util.Map<java.lang.String,DocumentField> fields)
-
-
Method Detail
-
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.
-
getIndex
public java.lang.String getIndex()
The index of the hit.
-
getId
public java.lang.String getId()
The id of the document.
-
getType
public java.lang.String getType()
The type of the document.
-
getNestedIdentity
public SearchHit.NestedIdentity getNestedIdentity()
If this is a nested hit then nested reference information is returned otherwisenullis 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 iffieldsdoesn't contain_sourceor if source is disabled in the mapping.
-
getSourceAsString
public java.lang.String getSourceAsString()
The source of the document as string (can benull).
-
getSourceAsMap
public java.util.Map<java.lang.String,java.lang.Object> getSourceAsMap()
The source of the document as a map (can benull).
-
iterator
public java.util.Iterator<DocumentField> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<DocumentField>
-
field
public DocumentField field(java.lang.String fieldName)
The hit field matching the given field name.
-
getFields
public java.util.Map<java.lang.String,DocumentField> getFields()
A map of hit fields (from field name to hit fields) if additional fields were required to be loaded.
-
fieldsOrNull
public java.util.Map<java.lang.String,DocumentField> fieldsOrNull()
-
fields
public void fields(java.util.Map<java.lang.String,DocumentField> fields)
-
getHighlightFields
public java.util.Map<java.lang.String,HighlightField> getHighlightFields()
A map of highlighted fields.
-
highlightFields
public void highlightFields(java.util.Map<java.lang.String,HighlightField> highlightFields)
-
sortValues
public void sortValues(java.lang.Object[] sortValues, DocValueFormat[] sortValueFormats)
-
sortValues
public void sortValues(SearchSortValues sortValues)
-
getSortValues
public java.lang.Object[] getSortValues()
An array of the sort values used.
-
getExplanation
public org.apache.lucene.search.Explanation getExplanation()
If enabled, the explanation of the search hit.
-
explanation
public void explanation(org.apache.lucene.search.Explanation explanation)
-
getShard
public SearchShardTarget getShard()
The shard of the search hit.
-
shard
public void shard(SearchShardTarget target)
-
getClusterAlias
public java.lang.String getClusterAlias()
Returns the cluster alias this hit comes from or null if it comes from a local cluster
-
matchedQueries
public void matchedQueries(java.lang.String[] matchedQueries)
-
getMatchedQueries
public java.lang.String[] getMatchedQueries()
The set of query and filter names the query matched with. Mainly makes sense for compound filters and queries.
-
getInnerHits
public java.util.Map<java.lang.String,SearchHits> getInnerHits()
- Returns:
- Inner hits or
nullif there are none
-
setInnerHits
public void setInnerHits(java.util.Map<java.lang.String,SearchHits> innerHits)
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
toXContentin interfaceToXContent- Throws:
java.io.IOException
-
toInnerXContent
public XContentBuilder toInnerXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Throws:
java.io.IOException
-
fromXContent
public static SearchHit fromXContent(XContentParser parser)
-
declareInnerHitsParseFields
public static void declareInnerHitsParseFields(ObjectParser<java.util.Map<java.lang.String,java.lang.Object>,java.lang.Void> parser)
-
createFromMap
public static SearchHit createFromMap(java.util.Map<java.lang.String,java.lang.Object> values)
-
readSearchHit
public static SearchHit readSearchHit(StreamInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
readFrom
public void readFrom(StreamInput in) throws java.io.IOException
Description copied from interface:StreamableSet this object's fields from a StreamInput.- Specified by:
readFromin interfaceStreamable- Throws:
java.io.IOException
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:StreamableWrite this object's fields to a StreamOutput.- Specified by:
writeToin interfaceStreamable- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-