Class SeqNoPrimaryTerm

java.lang.Object
org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm

public final class SeqNoPrimaryTerm extends Object

A container for seq_no and primary_term values. When an entity class contains a field of this type, it will be automatically filled with SeqNoPrimaryTerm instance on read operations (like get or search), and also, when the SeqNoPrimaryTerm is not null and filled with seq_no and primary_term, they will be sent to Elasticsearch when indexing such an entity.

This allows to implement optimistic locking pattern for full-update scenario, when an entity is first read from Elasticsearch and then gets reindexed with new _content. Index operations will throw an OptimisticLockingFailureException if the seq_no + primary_term pair already has different values for the given document. See Elasticsearch documentation for more information: https://www.elastic.co/guide/en/elasticsearch/reference/current/optimistic-concurrency-control.html

A property of this type is implicitly @Transient and never gets included into a mapping at Elasticsearch side.

A SeqNoPrimaryTerm instance cannot contain an invalid or unassigned seq_no or primary_term.

Since:
4.0
Author:
Roman Puchkovskiy
  • Constructor Details

    • SeqNoPrimaryTerm

      public SeqNoPrimaryTerm(long sequenceNumber, long primaryTerm)
      Creates an instance of SeqNoPrimaryTerm with the given seq_no and primary_term. The passed values are validated: sequenceNumber must be non-negative, primaryTerm must be positive. If validation fails, an IllegalArgumentException is thrown.
      Parameters:
      sequenceNumber - seq_no, must not be negative
      primaryTerm - primary_term, must be positive
      Throws:
      IllegalArgumentException - if seq_no or primary_term is not valid
  • Method Details

    • getSequenceNumber

      public long getSequenceNumber()
    • getPrimaryTerm

      public long getPrimaryTerm()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object