java.lang.Object
org.elasticsearch.search.SearchHit
- All Implemented Interfaces:
Writeable,RefCounted,ToXContent,ToXContentObject
A single search hit.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final classEncapsulates the nested identity of a hit.Nested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.ParamsNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
Fields inherited from interface org.elasticsearch.core.RefCounted
ALWAYS_REFERENCEDFields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY, EMPTY_PARAMS -
Constructor Summary
ConstructorsConstructorDescriptionSearchHit(int docId) SearchHit(int docId, float score, int rank, Text id, SearchHit.NestedIdentity nestedIdentity, long version, long seqNo, long primaryTerm, BytesReference source, Map<String, HighlightField> highlightFields, SearchSortValues sortValues, Map<String, Float> matchedQueries, org.apache.lucene.search.Explanation explanation, SearchShardTarget shard, String index, String clusterAlias, Map<String, SearchHits> innerHits, Map<String, DocumentField> documentFields, Map<String, DocumentField> metaFields, RefCounted refCounted) SearchHit(int nestedTopDocId, String id, SearchHit.NestedIdentity nestedIdentity) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDocumentFields(Map<String, DocumentField> docFields, Map<String, DocumentField> metaFields) booleandecRef()intdocId()booleanvoidexplanation(org.apache.lucene.search.Explanation explanation) The hit field matching the given field name.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.getMatchedQueryScore(String name) 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.intgetRank()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.longThe version of the hit.inthashCode()booleanWhether this search hit has any lookup fieldsbooleanbooleanIs the source available or not.voidhighlightFields(Map<String, HighlightField> highlightFields) voidincRef()booleanisPooled()voidmatchedQueries(Map<String, Float> matchedQueries) static SearchHitreadFrom(StreamInput in, boolean pooled) removeDocumentField(String field) voidresolveLookupFields(Map<LookupField, List<Object>> lookupResults) Resolve the lookup fields with the given results and merge them as regular fetch fields.voidscore(float score) voidsetDocumentField(String fieldName, DocumentField field) voidsetInnerHits(Map<String, SearchHits> innerHits) voidsetPrimaryTerm(long primaryTerm) voidsetRank(int rank) voidsetSeqNo(long seqNo) voidshard(SearchShardTarget target) voidsortValues(Object[] sortValues, DocValueFormat[] sortValueFormats) voidsortValues(SearchSortValues sortValues) sourceRef(BytesReference source) Sets representation, might be compressed....toInnerXContent(XContentBuilder builder, ToXContent.Params params) toString()toXContent(XContentBuilder builder, ToXContent.Params params) booleanstatic SearchHitunpooled(int docId) static SearchHitstatic SearchHitunpooled(int nestedTopDocId, String id, SearchHit.NestedIdentity nestedIdentity) 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 org.elasticsearch.core.RefCounted
mustIncRefMethods inherited from interface org.elasticsearch.xcontent.ToXContentObject
isFragment
-
Constructor Details
-
SearchHit
public SearchHit(int docId) -
SearchHit
-
SearchHit
-
SearchHit
public SearchHit(int docId, float score, int rank, Text id, SearchHit.NestedIdentity nestedIdentity, long version, long seqNo, long primaryTerm, BytesReference source, Map<String, HighlightField> highlightFields, SearchSortValues sortValues, Map<String, Float> matchedQueries, org.apache.lucene.search.Explanation explanation, SearchShardTarget shard, String index, String clusterAlias, Map<String, SearchHits> innerHits, Map<String, DocumentField> documentFields, Map<String, DocumentField> metaFields, @Nullable RefCounted refCounted)
-
-
Method Details
-
readFrom
- Throws:
IOException
-
unpooled
-
unpooled
-
unpooled
public static SearchHit unpooled(int nestedTopDocId, String id, SearchHit.NestedIdentity nestedIdentity) -
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. -
setRank
public void setRank(int rank) -
getRank
public int getRank() -
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. -
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). This method is expected to be called at most once during the lifetime of the object as the generated map is expensive to generate and it does not get cache. -
field
The hit field matching the given field name. -
setDocumentField
-
addDocumentFields
public void addDocumentFields(Map<String, DocumentField> docFields, Map<String, DocumentField> metaFields) -
removeDocumentField
-
getMetadataFields
- Returns:
- a map of metadata fields for this hit
-
getDocumentFields
- Returns:
- a map of non-metadata fields requested for this hit
-
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. -
hasLookupFields
public boolean hasLookupFields()Whether this search hit has any lookup fields -
resolveLookupFields
Resolve the lookup fields with the given results and merge them as regular fetch fields. -
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. -
getMatchedQueryScore
- Returns:
- The score of the provided named query if it matches,
nullotherwise.
-
getMatchedQueriesAndScores
- Returns:
- The map of the named queries that matched and their associated score.
-
getInnerHits
- Returns:
- Inner hits or
nullif there are none
-
setInnerHits
-
incRef
public void incRef()- Specified by:
incRefin interfaceRefCounted
-
tryIncRef
public boolean tryIncRef()- Specified by:
tryIncRefin interfaceRefCounted
-
decRef
public boolean decRef()- Specified by:
decRefin interfaceRefCounted
-
hasReferences
public boolean hasReferences()- Specified by:
hasReferencesin interfaceRefCounted
-
asUnpooled
-
isPooled
public boolean isPooled() -
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException - Specified by:
toXContentin interfaceToXContent- Throws:
IOException
-
toInnerXContent
public XContentBuilder toInnerXContent(XContentBuilder builder, ToXContent.Params params) throws IOException - Throws:
IOException
-
equals
-
hashCode
public int hashCode() -
toString
-