Class ShardId

java.lang.Object
org.opensearch.core.index.shard.ShardId
All Implemented Interfaces:
Comparable<ShardId>, Writeable, ToXContent, ToXContentFragment

@PublicApi(since="1.0.0") public class ShardId extends Object implements Comparable<ShardId>, ToXContentFragment, Writeable
Allows for shard level components to be injected with the shard id.
Opensearch.api:
  • Constructor Details

    • ShardId

      public ShardId(Index index, int shardId)
      Constructs a new shard id.
      Parameters:
      index - the index name
      shardId - the shard id
    • ShardId

      public ShardId(String index, String indexUUID, int shardId)
      Constructs a new shard id with the given index name, index unique identifier, and shard id.
      Parameters:
      index - the index name
      indexUUID - the index unique identifier
      shardId - the shard id
    • ShardId

      public ShardId(StreamInput in) throws IOException
      Constructs a new shardId from a stream.
      Parameters:
      in - the stream to read from
      Throws:
      IOException - if an error occurs while reading from the stream
      See Also:
  • Method Details

    • getBaseRamBytesUsed

      public long getBaseRamBytesUsed()
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Writes this shard id to a stream.
      Specified by:
      writeTo in interface Writeable
      Parameters:
      out - the stream to write to
      Throws:
      IOException - if an error occurs while writing to the stream
    • getIndex

      public Index getIndex()
      Returns the index of this shard id.
      Returns:
      the index of this shard id
    • getIndexName

      public String getIndexName()
      Returns the name of the index of this shard id.
      Returns:
      the name of the index of this shard id
    • id

      public int id()
      Return the shardId of this shard id.
      Returns:
      the shardId of this shard id
      See Also:
    • getId

      public int getId()
      Returns the shard id of this shard id.
      Returns:
      the shard id of this shard id
    • toString

      public String toString()
      Returns a string representation of this shard id.
      Overrides:
      toString in class Object
      Returns:
      "[indexName][shardId]"
    • fromString

      public static ShardId fromString(String shardIdString)
      Parse the string representation of this shardId back to an object.

      We lose index uuid information here, but since we use toString in rest responses, this is the best we can do to reconstruct the object on the client side.

      Parameters:
      shardIdString - the string representation of the shard id (Expect a string of format "[indexName][shardId]" (square brackets included))
    • equals

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

      public int hashCode()
      Returns the hash code of this shard id.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of this shard id
    • compareTo

      public int compareTo(ShardId o)
      Compares this ShardId with the specified ShardId.
      Specified by:
      compareTo in interface Comparable<ShardId>
      Parameters:
      o - the ShardId to be compared.
      Returns:
      a negative integer, zero, or a positive integer if this ShardId is less than, equal to, or greater than the specified ShardId
    • toXContent

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