Package org.elasticsearch.search
Class SearchHit
java.lang.Object
org.elasticsearch.search.SearchHit
- All Implemented Interfaces:
java.lang.Iterable<DocumentField>
,Writeable
,org.elasticsearch.common.xcontent.ToXContent
,org.elasticsearch.common.xcontent.ToXContentObject
public final class SearchHit extends java.lang.Object implements Writeable, org.elasticsearch.common.xcontent.ToXContentObject, java.lang.Iterable<DocumentField>
A single search hit.
- See Also:
SearchHits
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SearchHit.Fields
static class
SearchHit.NestedIdentity
Encapsulates the nested identity of a hit.Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
org.elasticsearch.common.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.common.xcontent.ToXContent.MapParams, org.elasticsearch.common.xcontent.ToXContent.Params
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Field Summary
Fields Modifier and Type Field Description static org.elasticsearch.common.xcontent.ObjectParser.UnknownFieldConsumer<java.util.Map<java.lang.String,java.lang.Object>>
unknownMetaFieldConsumer
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> documentFields, java.util.Map<java.lang.String,DocumentField> metaFields)
SearchHit(int nestedTopDocId, java.lang.String id, Text type, SearchHit.NestedIdentity nestedIdentity, java.util.Map<java.lang.String,DocumentField> documentFields, java.util.Map<java.lang.String,DocumentField> metaFields)
SearchHit(StreamInput in)
-
Method Summary
Modifier and Type Method Description static SearchHit
createFromMap(java.util.Map<java.lang.String,java.lang.Object> values)
static void
declareInnerHitsParseFields(org.elasticsearch.common.xcontent.ObjectParser<java.util.Map<java.lang.String,java.lang.Object>,java.lang.Void> parser)
int
docId()
boolean
equals(java.lang.Object obj)
void
explanation(org.apache.lucene.search.Explanation explanation)
DocumentField
field(java.lang.String fieldName)
The hit field matching the given field name.static SearchHit
fromXContent(org.elasticsearch.common.xcontent.XContentParser parser)
java.lang.String
getClusterAlias()
Returns the cluster alias this hit comes from or null if it comes from a local clusterorg.apache.lucene.search.Explanation
getExplanation()
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.String
getId()
The id of the document.java.lang.String
getIndex()
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.NestedIdentity
getNestedIdentity()
If this is a nested hit then nested reference information is returned otherwisenull
is returned.long
getPrimaryTerm()
returns the primary term of the last modification to the document, orSequenceNumbers.UNASSIGNED_PRIMARY_TERM
if not requested.java.lang.Object[]
getRawSortValues()
An array of the (raw) sort values used.float
getScore()
The score.long
getSeqNo()
returns the sequence number of the last modification to the document, orSequenceNumbers.UNASSIGNED_SEQ_NO
if not requested.SearchShardTarget
getShard()
The shard of the search hit.java.lang.Object[]
getSortValues()
An array of the (formatted) 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.String
getSourceAsString()
The source of the document as string (can benull
).BytesReference
getSourceRef()
Returns bytes reference, also uncompress the source if needed.java.lang.String
getType()
Deprecated.Types are in the process of being removed.long
getVersion()
The version of the hit.int
hashCode()
boolean
hasSource()
Is the source available or not.void
highlightFields(java.util.Map<java.lang.String,HighlightField> highlightFields)
java.util.Iterator<DocumentField>
iterator()
void
matchedQueries(java.lang.String[] matchedQueries)
void
score(float score)
void
setDocumentField(java.lang.String fieldName, DocumentField field)
void
setInnerHits(java.util.Map<java.lang.String,SearchHits> innerHits)
void
setPrimaryTerm(long primaryTerm)
void
setSeqNo(long seqNo)
void
shard(SearchShardTarget target)
void
sortValues(java.lang.Object[] sortValues, DocValueFormat[] sortValueFormats)
void
sortValues(SearchSortValues sortValues)
SearchHit
sourceRef(BytesReference source)
Sets representation, might be compressed....org.elasticsearch.common.xcontent.XContentBuilder
toInnerXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
java.lang.String
toString()
org.elasticsearch.common.xcontent.XContentBuilder
toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
void
version(long version)
void
writeTo(StreamOutput out)
Write this into the StreamOutput.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
Field Details
-
unknownMetaFieldConsumer
public static final org.elasticsearch.common.xcontent.ObjectParser.UnknownFieldConsumer<java.util.Map<java.lang.String,java.lang.Object>> unknownMetaFieldConsumer
-
-
Constructor Details
-
SearchHit
public SearchHit(int docId) -
SearchHit
public SearchHit(int docId, java.lang.String id, Text type, java.util.Map<java.lang.String,DocumentField> documentFields, java.util.Map<java.lang.String,DocumentField> metaFields) -
SearchHit
public SearchHit(int nestedTopDocId, java.lang.String id, Text type, SearchHit.NestedIdentity nestedIdentity, java.util.Map<java.lang.String,DocumentField> documentFields, java.util.Map<java.lang.String,DocumentField> metaFields) -
SearchHit
- Throws:
java.io.IOException
-
-
Method Details
-
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput. -
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, orSequenceNumbers.UNASSIGNED_SEQ_NO
if not requested. -
getPrimaryTerm
public long getPrimaryTerm()returns the primary term of the last modification to the document, orSequenceNumbers.UNASSIGNED_PRIMARY_TERM
if not requested. -
getIndex
public java.lang.String getIndex()The index of the hit. -
getId
public java.lang.String getId()The id of the document. -
getType
@Deprecated public java.lang.String getType()Deprecated.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
If this is a nested hit then nested reference information is returned otherwisenull
is returned. -
getSourceRef
Returns bytes reference, also uncompress the source if needed. -
sourceRef
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 iffields
doesn't contain_source
or 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
- Specified by:
iterator
in interfacejava.lang.Iterable<DocumentField>
-
field
The hit field matching the given field name. -
setDocumentField
-
getFields
A map of hit fields (from field name to hit fields) if additional fields were required to be loaded. -
getHighlightFields
A map of highlighted fields. -
highlightFields
-
sortValues
-
sortValues
-
getSortValues
public java.lang.Object[] getSortValues()An array of the (formatted) sort values used. -
getRawSortValues
public java.lang.Object[] getRawSortValues()An array of the (raw) 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
The shard of the search hit. -
shard
-
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
- Returns:
- Inner hits or
null
if there are none
-
setInnerHits
-
toXContent
public org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException- Specified by:
toXContent
in interfaceorg.elasticsearch.common.xcontent.ToXContent
- Throws:
java.io.IOException
-
toInnerXContent
public org.elasticsearch.common.xcontent.XContentBuilder toInnerXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException- Throws:
java.io.IOException
-
fromXContent
-
declareInnerHitsParseFields
public static void declareInnerHitsParseFields(org.elasticsearch.common.xcontent.ObjectParser<java.util.Map<java.lang.String,java.lang.Object>,java.lang.Void> parser) -
createFromMap
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-