Class GetResponse

All Implemented Interfaces:
Iterable<DocumentField>, Writeable, RefCounted, ToXContent, ToXContentObject

public class GetResponse extends ActionResponse implements Iterable<DocumentField>, ToXContentObject
The response of a get action.
See Also:
  • Constructor Details

    • GetResponse

      public GetResponse(GetResult getResult)
  • Method Details

    • isExists

      public boolean isExists()
      Does the document exists.
    • getIndex

      public String getIndex()
      The index the document was fetched from.
    • getType

      public String getType()
      The type of the document.
    • getId

      public 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 String getSourceAsString()
      The source of the document (as a string).
    • getSourceAsMap

      public Map<String,Object> getSourceAsMap() throws ElasticsearchParseException
      The source of the document (As a map).
    • getSource

      public Map<String,Object> getSource()
    • getFields

      public Map<String,DocumentField> getFields()
    • getField

      public DocumentField getField(String name)
    • iterator

      @Deprecated public Iterator<DocumentField> iterator()
      Use getSource() instead
      Specified by:
      iterator in interface Iterable<DocumentField>
    • toXContent

      public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
      Specified by:
      toXContent in interface ToXContent
    • fromXContent

      public static GetResponse fromXContent(XContentParser parser) throws IOException
      This method can be used to parse a GetResponse object when it has been printed out as a xcontent using the toXContent(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 a ParsingException otherwise. This is the case when we get a 404 back, which can be parsed as a normal GetResponse 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.

      parser - XContentParser to parse the response from
      a GetResponse
      IOException - is an I/O exception occurs during the parsing
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
    • equals

      public boolean equals(Object o)
      equals in class Object
    • hashCode

      public int hashCode()
      hashCode in class Object
    • toString

      public String toString()
      toString in class Object