Package org.elasticsearch.search
Class SearchHit
java.lang.Object
org.elasticsearch.search.SearchHit
- All Implemented Interfaces:
Iterable<DocumentField>,Writeable,org.elasticsearch.common.xcontent.ToXContent,org.elasticsearch.common.xcontent.ToXContentObject
public final class SearchHit
extends Object
implements Writeable, org.elasticsearch.common.xcontent.ToXContentObject, Iterable<DocumentField>
A single search hit.
- See Also:
SearchHits
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classEncapsulates 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.ParamsNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionFields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS -
Constructor Summary
ConstructorsConstructorDescriptionSearchHit(int docId)SearchHit(int docId, String id, Text type, Map<String,DocumentField> documentFields, Map<String,DocumentField> metaFields)SearchHit(int nestedTopDocId, String id, Text type, SearchHit.NestedIdentity nestedIdentity, Map<String,DocumentField> documentFields, Map<String,DocumentField> metaFields)SearchHit(StreamInput in) -
Method Summary
Modifier and TypeMethodDescriptionstatic SearchHitcreateFromMap(Map<String,Object> values)static voiddeclareInnerHitsParseFields(org.elasticsearch.common.xcontent.ObjectParser<Map<String,Object>,Void> parser)intdocId()booleanvoidexplanation(org.apache.lucene.search.Explanation explanation)The hit field matching the given field name.static SearchHitfromXContent(org.elasticsearch.common.xcontent.XContentParser parser)Returns the cluster alias this hit comes from or null if it comes from a local clusterorg.apache.lucene.search.ExplanationIf enabled, the explanation of the search hit.A map of hit fields (from field name to hit fields) if additional fields were required to be loaded.A map of highlighted fields.getId()The id of the document.getIndex()The index of the hit.String[]The set of query and filter names the query matched with.If this is a nested hit then nested reference information is returned otherwisenullis returned.longreturns the primary term of the last modification to the document, orSequenceNumbers.UNASSIGNED_PRIMARY_TERMif not requested.Object[]An array of the (raw) sort values used.floatgetScore()The score.longgetSeqNo()returns the sequence number of the last modification to the document, orSequenceNumbers.UNASSIGNED_SEQ_NOif not requested.getShard()The shard of the search hit.Object[]An array of the (formatted) sort values used.The source of the document as a map (can benull).The source of the document as string (can benull).Returns bytes reference, also uncompress the source if needed.getType()Deprecated.Types are in the process of being removed.longThe version of the hit.inthashCode()booleanIs the source available or not.voidhighlightFields(Map<String,HighlightField> highlightFields)iterator()voidmatchedQueries(String[] matchedQueries)voidscore(float score)voidsetDocumentField(String fieldName, DocumentField field)voidsetInnerHits(Map<String,SearchHits> innerHits)voidsetPrimaryTerm(long primaryTerm)voidsetSeqNo(long seqNo)voidshard(SearchShardTarget target)voidsortValues(Object[] sortValues, DocValueFormat[] sortValueFormats)voidsortValues(SearchSortValues sortValues)sourceRef(BytesReference source)Sets representation, might be compressed....org.elasticsearch.common.xcontent.XContentBuildertoInnerXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)toString()org.elasticsearch.common.xcontent.XContentBuildertoXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)voidversion(long version)voidwriteTo(StreamOutput out)Write this into the StreamOutput.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
Field Details
-
unknownMetaFieldConsumer
-
-
Constructor Details
-
SearchHit
public SearchHit(int docId) -
SearchHit
public SearchHit(int docId, String id, Text type, Map<String,DocumentField> documentFields, Map<String,DocumentField> metaFields) -
SearchHit
public SearchHit(int nestedTopDocId, String id, Text type, SearchHit.NestedIdentity nestedIdentity, Map<String,DocumentField> documentFields, Map<String,DocumentField> metaFields) -
SearchHit
- Throws:
IOException
-
-
Method Details
-
writeTo
Description copied from interface:WriteableWrite this into the StreamOutput.- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
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_NOif not requested. -
getPrimaryTerm
public long getPrimaryTerm()returns the primary term of the last modification to the document, orSequenceNumbers.UNASSIGNED_PRIMARY_TERMif not requested. -
getIndex
The index of the hit. -
getId
The id of the document. -
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 otherwisenullis 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 iffieldsdoesn't contain_sourceor if source is disabled in the mapping. -
getSourceAsString
The source of the document as string (can benull). -
getSourceAsMap
The source of the document as a map (can benull). -
iterator
- Specified by:
iteratorin interfaceIterable<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
An array of the (formatted) sort values used. -
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
Returns the cluster alias this hit comes from or null if it comes from a local cluster -
matchedQueries
-
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
nullif 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 IOException- Specified by:
toXContentin interfaceorg.elasticsearch.common.xcontent.ToXContent- Throws:
IOException
-
toInnerXContent
public org.elasticsearch.common.xcontent.XContentBuilder toInnerXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws IOException- Throws:
IOException
-
fromXContent
-
declareInnerHitsParseFields
-
createFromMap
-
equals
-
hashCode
public int hashCode() -
toString
-