Package org.elasticsearch.action.get
Class GetResponse
- java.lang.Object
-
- org.elasticsearch.transport.TransportMessage
-
- org.elasticsearch.transport.TransportResponse
-
- org.elasticsearch.action.ActionResponse
-
- org.elasticsearch.action.get.GetResponse
-
- All Implemented Interfaces:
java.lang.Iterable<DocumentField>
,Streamable
,Writeable
,ToXContent
,ToXContentObject
public class GetResponse extends ActionResponse implements java.lang.Iterable<DocumentField>, ToXContentObject
The response of a get action.- See Also:
GetRequest
,Client.get(GetRequest)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.elasticsearch.transport.TransportResponse
TransportResponse.Empty
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested 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.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description GetResponse(GetResult getResult)
-
Method Summary
Modifier and Type Method Description boolean
equals(java.lang.Object o)
static GetResponse
fromXContent(XContentParser parser)
This method can be used to parse aGetResponse
object when it has been printed out as a xcontent using thetoXContent(XContentBuilder, Params)
method.DocumentField
getField(java.lang.String name)
java.util.Map<java.lang.String,DocumentField>
getFields()
java.lang.String
getId()
The id of the document.java.lang.String
getIndex()
The index the document was fetched from.long
getPrimaryTerm()
The primary term of the last primary that has changed this document, if found.long
getSeqNo()
The sequence number assigned to the last operation that has changed this document, if found.java.util.Map<java.lang.String,java.lang.Object>
getSource()
byte[]
getSourceAsBytes()
The source of the document if exists.BytesReference
getSourceAsBytesRef()
Returns bytes reference, also un compress the source if needed.java.util.Map<java.lang.String,java.lang.Object>
getSourceAsMap()
The source of the document (As a map).java.lang.String
getSourceAsString()
The source of the document (as a string).BytesReference
getSourceInternal()
Returns the internal source bytes, as they are returned without munging (for example, might still be compressed).java.lang.String
getType()
The type of the document.long
getVersion()
The version of the doc.int
hashCode()
boolean
isExists()
Does the document exists.boolean
isSourceEmpty()
Is the source empty (not available) or not.java.util.Iterator<DocumentField>
iterator()
Deprecated.UsegetSource()
insteadvoid
readFrom(StreamInput in)
Set this object's fields from a StreamInput.java.lang.String
toString()
XContentBuilder
toXContent(XContentBuilder builder, ToXContent.Params params)
void
writeTo(StreamOutput out)
Write this object's fields to a StreamOutput.-
Methods inherited from class org.elasticsearch.transport.TransportMessage
remoteAddress, remoteAddress
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Constructor Detail
-
GetResponse
public GetResponse(GetResult getResult)
-
-
Method Detail
-
isExists
public boolean isExists()
Does the document exists.
-
getIndex
public java.lang.String getIndex()
The index the document was fetched from.
-
getType
public java.lang.String getType()
The type of the document.
-
getId
public java.lang.String getId()
The id of the document.
-
getVersion
public long getVersion()
The version of the doc.
-
getSeqNo
public long getSeqNo()
The sequence number assigned to the last operation that has changed this document, if found.
-
getPrimaryTerm
public long getPrimaryTerm()
The primary term of the last primary that has changed this document, if found.
-
getSourceAsBytes
public byte[] getSourceAsBytes()
The source of the document if exists.
-
getSourceInternal
public BytesReference getSourceInternal()
Returns the internal source bytes, as they are returned without munging (for example, might still be compressed).
-
getSourceAsBytesRef
public BytesReference getSourceAsBytesRef()
Returns bytes reference, also un compress the source if needed.
-
isSourceEmpty
public boolean isSourceEmpty()
Is the source empty (not available) or not.
-
getSourceAsString
public java.lang.String getSourceAsString()
The source of the document (as a string).
-
getSourceAsMap
public java.util.Map<java.lang.String,java.lang.Object> getSourceAsMap() throws ElasticsearchParseException
The source of the document (As a map).- Throws:
ElasticsearchParseException
-
getSource
public java.util.Map<java.lang.String,java.lang.Object> getSource()
-
getFields
public java.util.Map<java.lang.String,DocumentField> getFields()
-
getField
public DocumentField getField(java.lang.String name)
-
iterator
@Deprecated public java.util.Iterator<DocumentField> iterator()
Deprecated.UsegetSource()
instead- Specified by:
iterator
in interfacejava.lang.Iterable<DocumentField>
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
toXContent
in interfaceToXContent
- Throws:
java.io.IOException
-
fromXContent
public static GetResponse fromXContent(XContentParser parser) throws java.io.IOException
This method can be used to parse aGetResponse
object when it has been printed out as a xcontent using thetoXContent(XContentBuilder, Params)
method.For forward compatibility reason this method might not fail if it tries to parse a field it doesn't know. But before returning the result it will check that enough information were parsed to return a valid
GetResponse
instance and throws aParsingException
otherwise. This is the case when we get a 404 back, which can be parsed as a normalGetResponse
with found set to false, or as an elasticsearch exception. The caller of this method needs a way to figure out whether we got back a valid get response, which can be done by catching ParsingException.- Parameters:
parser
-XContentParser
to parse the response from- Returns:
- a
GetResponse
- Throws:
java.io.IOException
- is an I/O exception occurs during the parsing
-
readFrom
public void readFrom(StreamInput in) throws java.io.IOException
Description copied from interface:Streamable
Set this object's fields from a StreamInput.- Specified by:
readFrom
in interfaceStreamable
- Overrides:
readFrom
in classActionResponse
- Throws:
java.io.IOException
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:Streamable
Write this object's fields to a StreamOutput.- Specified by:
writeTo
in interfaceStreamable
- Specified by:
writeTo
in interfaceWriteable
- Overrides:
writeTo
in classActionResponse
- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object o)
- 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
-
-