All Superinterfaces:
Map<String,Object>, StringObjectMap<Document>
All Known Subinterfaces:
SearchDocument
All Known Implementing Classes:
SearchDocumentAdapter

public interface Document extends StringObjectMap<Document>
A representation of a Elasticsearch document as extended Map. All iterators preserve original insertion order.

Document does not allow null keys. It allows null values.

Implementing classes can bei either mutable or immutable. In case a subclass is immutable, its methods may throw UnsupportedOperationException when calling modifying methods.

Since:
4.0
Author:
Mark Paluch, Peter-Josef Meisch, Roman Puchkovskiy
  • Method Details

    • create

      static Document create()
      Create a new mutable Document.
      Returns:
      a new Document.
    • from

      static Document from(Map<String,? extends Object> map)
      Create a Document from a Map containing key-value pairs and sub-documents.
      Parameters:
      map - source map containing key-value pairs and sub-documents. must not be null.
      Returns:
      a new Document.
    • parse

      static Document parse(String json)
      Parse JSON to Document.
      Parameters:
      json - must not be null.
      Returns:
      the parsed Document.
    • fromJson

      default Document fromJson(String json)
      Description copied from interface: StringObjectMap
      initializes this object from the given JSON String.
      Specified by:
      fromJson in interface StringObjectMap<Document>
      Parameters:
      json - must not be null
    • hasId

      default boolean hasId()
      Return true if this Document is associated with an identifier.
      Returns:
      true if this Document is associated with an identifier, false otherwise.
    • getIndex

      @Nullable default String getIndex()
      Returns:
      the index if this document was retrieved from an index or was just stored.
      Since:
      4.1
    • setIndex

      default void setIndex(@Nullable String index)
      Sets the index name for this document
      Parameters:
      index - index name

      The default implementation throws UnsupportedOperationException.

      Since:
      4.1
    • getId

      default String getId()
      Retrieve the identifier associated with this Document.

      The default implementation throws UnsupportedOperationException. It's recommended to check hasId() prior to calling this method.

      Returns:
      the identifier associated with this Document.
      Throws:
      IllegalStateException - if the underlying implementation supports Id's but no Id was yet associated with the document.
    • setId

      default void setId(String id)
      Set the identifier for this Document.

      The default implementation throws UnsupportedOperationException.

    • hasVersion

      default boolean hasVersion()
      Return true if this Document is associated with a version.
      Returns:
      true if this Document is associated with a version, false otherwise.
    • getVersion

      default long getVersion()
      Retrieve the version associated with this Document.

      The default implementation throws UnsupportedOperationException. It's recommended to check hasVersion() prior to calling this method.

      Returns:
      the version associated with this Document.
      Throws:
      IllegalStateException - if the underlying implementation supports Id's but no Id was yet associated with the document.
    • setVersion

      default void setVersion(long version)
      Set the version for this Document.

      The default implementation throws UnsupportedOperationException.

    • hasSeqNo

      default boolean hasSeqNo()
      Return true if this Document is associated with a seq_no.
      Returns:
      true if this Document is associated with a seq_no, false otherwise.
    • getSeqNo

      default long getSeqNo()
      Retrieve the seq_no associated with this Document.

      The default implementation throws UnsupportedOperationException. It's recommended to check hasSeqNo() prior to calling this method.

      Returns:
      the seq_no associated with this Document.
      Throws:
      IllegalStateException - if the underlying implementation supports seq_no's but no seq_no was yet associated with the document.
    • setSeqNo

      default void setSeqNo(long seqNo)
      Set the seq_no for this Document.

      The default implementation throws UnsupportedOperationException.

    • hasPrimaryTerm

      default boolean hasPrimaryTerm()
      Return true if this Document is associated with a primary_term.
      Returns:
      true if this Document is associated with a primary_term, false otherwise.
    • getPrimaryTerm

      default long getPrimaryTerm()
      Retrieve the primary_term associated with this Document.

      The default implementation throws UnsupportedOperationException. It's recommended to check hasPrimaryTerm() prior to calling this method.

      Returns:
      the primary_term associated with this Document.
      Throws:
      IllegalStateException - if the underlying implementation supports primary_term's but no primary_term was yet associated with the document.
    • setPrimaryTerm

      default void setPrimaryTerm(long primaryTerm)
      Set the primary_term for this Document.

      The default implementation throws UnsupportedOperationException.

    • transform

      default <R> R transform(Function<? super Document,? extends R> transformer)
      This method allows the application of a function to this Document. The function should expect a single Document argument and produce an R result.

      Any exception thrown by the function will be propagated to the caller.

      Type Parameters:
      R - class of the result
      Parameters:
      transformer - functional interface to a apply. must not be null.
      Returns:
      the result of applying the function to this string
      See Also: