Class IndexMetadata

java.lang.Object
org.elasticsearch.cluster.metadata.IndexMetadata
All Implemented Interfaces:
Diffable<IndexMetadata>, Writeable, ToXContent, ToXContentFragment

public class IndexMetadata extends Object implements Diffable<IndexMetadata>, ToXContentFragment
  • Field Details

    • INDEX_READ_ONLY_BLOCK

      public static final ClusterBlock INDEX_READ_ONLY_BLOCK
    • INDEX_READ_BLOCK

      public static final ClusterBlock INDEX_READ_BLOCK
    • INDEX_WRITE_BLOCK

      public static final ClusterBlock INDEX_WRITE_BLOCK
    • INDEX_METADATA_BLOCK

      public static final ClusterBlock INDEX_METADATA_BLOCK
    • INDEX_READ_ONLY_ALLOW_DELETE_BLOCK

      public static final ClusterBlock INDEX_READ_ONLY_ALLOW_DELETE_BLOCK
    • INDEX_SETTING_PREFIX

      public static final String INDEX_SETTING_PREFIX
      See Also:
    • SETTING_NUMBER_OF_SHARDS

      public static final String SETTING_NUMBER_OF_SHARDS
      See Also:
    • INDEX_NUMBER_OF_SHARDS_SETTING

      public static final Setting<Integer> INDEX_NUMBER_OF_SHARDS_SETTING
    • SETTING_NUMBER_OF_REPLICAS

      public static final String SETTING_NUMBER_OF_REPLICAS
      See Also:
    • INDEX_NUMBER_OF_REPLICAS_SETTING

      public static final Setting<Integer> INDEX_NUMBER_OF_REPLICAS_SETTING
    • SETTING_ROUTING_PARTITION_SIZE

      public static final String SETTING_ROUTING_PARTITION_SIZE
      See Also:
    • INDEX_ROUTING_PARTITION_SIZE_SETTING

      public static final Setting<Integer> INDEX_ROUTING_PARTITION_SIZE_SETTING
    • INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING

      public static final Setting<Integer> INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING
    • SETTING_AUTO_EXPAND_REPLICAS

      public static final String SETTING_AUTO_EXPAND_REPLICAS
      See Also:
    • INDEX_AUTO_EXPAND_REPLICAS_SETTING

      public static final Setting<AutoExpandReplicas> INDEX_AUTO_EXPAND_REPLICAS_SETTING
    • SETTING_READ_ONLY

      public static final String SETTING_READ_ONLY
    • INDEX_READ_ONLY_SETTING

      public static final Setting<Boolean> INDEX_READ_ONLY_SETTING
    • SETTING_BLOCKS_READ

      public static final String SETTING_BLOCKS_READ
    • INDEX_BLOCKS_READ_SETTING

      public static final Setting<Boolean> INDEX_BLOCKS_READ_SETTING
    • SETTING_BLOCKS_WRITE

      public static final String SETTING_BLOCKS_WRITE
    • INDEX_BLOCKS_WRITE_SETTING

      public static final Setting<Boolean> INDEX_BLOCKS_WRITE_SETTING
    • SETTING_BLOCKS_METADATA

      public static final String SETTING_BLOCKS_METADATA
    • INDEX_BLOCKS_METADATA_SETTING

      public static final Setting<Boolean> INDEX_BLOCKS_METADATA_SETTING
    • SETTING_READ_ONLY_ALLOW_DELETE

      public static final String SETTING_READ_ONLY_ALLOW_DELETE
    • INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING

      public static final Setting<Boolean> INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING
    • SETTING_VERSION_CREATED

      public static final String SETTING_VERSION_CREATED
      See Also:
    • SETTING_INDEX_VERSION_CREATED

      public static final Setting<Version> SETTING_INDEX_VERSION_CREATED
    • SETTING_VERSION_CREATED_STRING

      public static final String SETTING_VERSION_CREATED_STRING
      See Also:
    • SETTING_CREATION_DATE

      public static final String SETTING_CREATION_DATE
      See Also:
    • SETTING_VERSION_UPGRADED

      @Deprecated public static final String SETTING_VERSION_UPGRADED
      Deprecated.
      These internal settings are no longer added to new indices. They are deprecated but still defined to retain compatibility with old indexes. TODO: remove in 9.0.
      See Also:
    • SETTING_VERSION_UPGRADED_STRING

      @Deprecated public static final String SETTING_VERSION_UPGRADED_STRING
      Deprecated.
      See Also:
    • SETTING_VERSION_COMPATIBILITY

      public static final String SETTING_VERSION_COMPATIBILITY
      See Also:
    • SETTING_INDEX_VERSION_COMPATIBILITY

      public static final Setting<Version> SETTING_INDEX_VERSION_COMPATIBILITY
    • SETTING_INDEX_PROVIDED_NAME

      public static final String SETTING_INDEX_PROVIDED_NAME
      The user provided name for an index. This is the plain string provided by the user when the index was created. It might still contain date math expressions etc. (added in 5.0)
      See Also:
    • SETTING_PRIORITY

      public static final String SETTING_PRIORITY
      See Also:
    • INDEX_PRIORITY_SETTING

      public static final Setting<Integer> INDEX_PRIORITY_SETTING
    • SETTING_CREATION_DATE_STRING

      public static final String SETTING_CREATION_DATE_STRING
      See Also:
    • SETTING_INDEX_UUID

      public static final String SETTING_INDEX_UUID
      See Also:
    • SETTING_HISTORY_UUID

      public static final String SETTING_HISTORY_UUID
      See Also:
    • SETTING_DATA_PATH

      public static final String SETTING_DATA_PATH
      See Also:
    • INDEX_DATA_PATH_SETTING

      public static final Setting<String> INDEX_DATA_PATH_SETTING
    • INDEX_UUID_NA_VALUE

      public static final String INDEX_UUID_NA_VALUE
      See Also:
    • INDEX_ROUTING_REQUIRE_GROUP_PREFIX

      public static final String INDEX_ROUTING_REQUIRE_GROUP_PREFIX
      See Also:
    • INDEX_ROUTING_INCLUDE_GROUP_PREFIX

      public static final String INDEX_ROUTING_INCLUDE_GROUP_PREFIX
      See Also:
    • INDEX_ROUTING_EXCLUDE_GROUP_PREFIX

      public static final String INDEX_ROUTING_EXCLUDE_GROUP_PREFIX
      See Also:
    • INDEX_ROUTING_REQUIRE_GROUP_SETTING

      public static final Setting.AffixSetting<List<String>> INDEX_ROUTING_REQUIRE_GROUP_SETTING
    • INDEX_ROUTING_INCLUDE_GROUP_SETTING

      public static final Setting.AffixSetting<List<String>> INDEX_ROUTING_INCLUDE_GROUP_SETTING
    • INDEX_ROUTING_EXCLUDE_GROUP_SETTING

      public static final Setting.AffixSetting<List<String>> INDEX_ROUTING_EXCLUDE_GROUP_SETTING
    • INDEX_ROUTING_INITIAL_RECOVERY_GROUP_SETTING

      public static final Setting.AffixSetting<List<String>> INDEX_ROUTING_INITIAL_RECOVERY_GROUP_SETTING
    • SETTING_WAIT_FOR_ACTIVE_SHARDS

      public static final Setting<ActiveShardCount> SETTING_WAIT_FOR_ACTIVE_SHARDS
      The number of active shard copies to check for before proceeding with a write operation.
    • SETTING_INDEX_HIDDEN

      public static final String SETTING_INDEX_HIDDEN
      See Also:
    • INDEX_HIDDEN_SETTING

      public static final Setting<Boolean> INDEX_HIDDEN_SETTING
      Whether the index is considered hidden or not. A hidden index will not be resolved in normal wildcard searches unless explicitly allowed
    • INDEX_FORMAT_SETTING

      public static final Setting<Integer> INDEX_FORMAT_SETTING
    • INDEX_ROUTING_PATH

      public static final Setting<List<String>> INDEX_ROUTING_PATH
    • INDEX_ROLLUP_SOURCE_UUID

      @Deprecated public static final Setting<String> INDEX_ROLLUP_SOURCE_UUID
      Deprecated.
      Legacy index setting, kept for 7.x BWC compatibility. This setting has no effect in 8.x. Do not use. TODO: Remove in 9.0
    • INDEX_ROLLUP_SOURCE_NAME

      @Deprecated public static final Setting<String> INDEX_ROLLUP_SOURCE_NAME
      Deprecated.
      Legacy index setting, kept for 7.x BWC compatibility. This setting has no effect in 8.x. Do not use. TODO: Remove in 9.0
    • KEY_IN_SYNC_ALLOCATIONS

      public static final String KEY_IN_SYNC_ALLOCATIONS
      See Also:
    • KEY_PRIMARY_TERMS

      public static final String KEY_PRIMARY_TERMS
      See Also:
    • KEY_STATS

      public static final String KEY_STATS
      See Also:
    • KEY_WRITE_LOAD_FORECAST

      public static final String KEY_WRITE_LOAD_FORECAST
      See Also:
    • KEY_SHARD_SIZE_FORECAST

      public static final String KEY_SHARD_SIZE_FORECAST
      See Also:
    • INDEX_STATE_FILE_PREFIX

      public static final String INDEX_STATE_FILE_PREFIX
      See Also:
    • INDEX_RESIZE_SOURCE_UUID_KEY

      public static final String INDEX_RESIZE_SOURCE_UUID_KEY
      See Also:
    • INDEX_RESIZE_SOURCE_NAME_KEY

      public static final String INDEX_RESIZE_SOURCE_NAME_KEY
      See Also:
    • INDEX_RESIZE_SOURCE_UUID

      public static final Setting<String> INDEX_RESIZE_SOURCE_UUID
    • INDEX_RESIZE_SOURCE_NAME

      public static final Setting<String> INDEX_RESIZE_SOURCE_NAME
    • INDEX_SHRINK_INITIAL_RECOVERY_KEY

      public static final String INDEX_SHRINK_INITIAL_RECOVERY_KEY
      we use "i.r.a.initial_recovery" rather than "i.r.a.require|include" since we want the replica to allocate right away once we are allocated.
    • INDEX_DOWNSAMPLE_SOURCE_UUID_KEY

      public static final String INDEX_DOWNSAMPLE_SOURCE_UUID_KEY
      See Also:
    • INDEX_DOWNSAMPLE_SOURCE_NAME_KEY

      public static final String INDEX_DOWNSAMPLE_SOURCE_NAME_KEY
      See Also:
    • INDEX_DOWNSAMPLE_STATUS_KEY

      public static final String INDEX_DOWNSAMPLE_STATUS_KEY
      See Also:
    • INDEX_DOWNSAMPLE_SOURCE_UUID

      public static final Setting<String> INDEX_DOWNSAMPLE_SOURCE_UUID
    • INDEX_DOWNSAMPLE_SOURCE_NAME

      public static final Setting<String> INDEX_DOWNSAMPLE_SOURCE_NAME
    • INDEX_DOWNSAMPLE_STATUS

      public static final Setting<IndexMetadata.DownsampleTaskStatus> INDEX_DOWNSAMPLE_STATUS
    • LIFECYCLE_NAME

      public static final String LIFECYCLE_NAME
      See Also:
    • FORMAT

      public static final MetadataStateFormat<IndexMetadata> FORMAT
      State format for IndexMetadata to write to and load from disk
  • Method Details

    • isDownsampledIndex

      public boolean isDownsampledIndex()
    • withInSyncAllocationIds

      public IndexMetadata withInSyncAllocationIds(int shardId, Set<String> inSyncSet)
      Copy constructor that sets the in-sync allocation ids for the specified shard.
      Parameters:
      shardId - shard id to set in-sync allocation ids for
      inSyncSet - new in-sync allocation ids
      Returns:
      updated instance
    • withIncrementedPrimaryTerm

      public IndexMetadata withIncrementedPrimaryTerm(int shardId)
      Creates a copy of this instance that has the primary term for the given shard id incremented.
      Parameters:
      shardId - shard id to increment primary term for
      Returns:
      updated instance with incremented primary term
    • withTimestampRange

      public IndexMetadata withTimestampRange(IndexLongFieldRange timestampRange)
      Parameters:
      timestampRange - new timestamp range
      Returns:
      copy of this instance with updated timestamp range
    • withIncrementedVersion

      public IndexMetadata withIncrementedVersion()
      Returns:
      a copy of this instance that has its version incremented by one
    • getIndex

      public Index getIndex()
    • getIndexUUID

      public String getIndexUUID()
    • getVersion

      public long getVersion()
    • getMappingVersion

      public long getMappingVersion()
    • getSettingsVersion

      public long getSettingsVersion()
    • getAliasesVersion

      public long getAliasesVersion()
    • primaryTerm

      public long primaryTerm(int shardId)
      The term of the current selected primary. This is a non-negative number incremented when a primary shard is assigned after a full cluster restart or a replica shard is promoted to a primary. Note: since we increment the term every time a shard is assigned, the term for any operational shard (i.e., a shard that can be indexed into) is larger than 0. See IndexMetadataUpdater.applyChanges(org.elasticsearch.cluster.metadata.Metadata, org.elasticsearch.cluster.routing.RoutingTable).
    • getCreationVersion

      public Version getCreationVersion()
      Return the Version on which this index has been created. This information is typically useful for backward compatibility. To check index compatibility (e.g. N-1 checks), use getCompatibilityVersion() instead.
    • getCompatibilityVersion

      public Version getCompatibilityVersion()
      Return the Version that this index provides compatibility for. This is typically compared to the Version.minimumIndexCompatibilityVersion() to figure out whether the index can be handled by the cluster. By default, this is equal to the getCreationVersion(), but can also be a newer version if the index has been imported as a legacy index from an older snapshot, and its metadata has been converted to be handled by newer version nodes.
    • getCreationDate

      public long getCreationDate()
    • getState

      public IndexMetadata.State getState()
    • getNumberOfShards

      public int getNumberOfShards()
    • getNumberOfReplicas

      public int getNumberOfReplicas()
    • getRoutingPartitionSize

      public int getRoutingPartitionSize()
    • isRoutingPartitionedIndex

      public boolean isRoutingPartitionedIndex()
    • getRoutingPaths

      public List<String> getRoutingPaths()
    • getTotalNumberOfShards

      public int getTotalNumberOfShards()
    • getWaitForActiveShards

      public ActiveShardCount getWaitForActiveShards()
      Returns the configured SETTING_WAIT_FOR_ACTIVE_SHARDS, which defaults to an active shard count of 1 if not specified.
    • ignoreDiskWatermarks

      public boolean ignoreDiskWatermarks()
    • getSettings

      public Settings getSettings()
    • getAliases

      public Map<String,AliasMetadata> getAliases()
    • getShardsPerNodeLimit

      public int getShardsPerNodeLimit()
    • getTierPreference

      public List<String> getTierPreference()
    • getLifecyclePolicyName

      @Nullable public String getLifecyclePolicyName()
      Return the name of the Index Lifecycle Policy associated with this index, or null if it is not managed by ILM.
    • getLifecycleExecutionState

      public LifecycleExecutionState getLifecycleExecutionState()
    • getAutoExpandReplicas

      public AutoExpandReplicas getAutoExpandReplicas()
    • isSearchableSnapshot

      public boolean isSearchableSnapshot()
    • isPartialSearchableSnapshot

      public boolean isPartialSearchableSnapshot()
    • getIndexMode

      @Nullable public IndexMode getIndexMode()
      Returns:
      the mode this index is in. This determines the behaviour and features it supports. If null is returned then this in index is in standard mode.
    • getTimeSeriesStart

      @Nullable public Instant getTimeSeriesStart()
      If this index is in IndexMode.TIME_SERIES then this returns the lower boundary of the time series time range. Together with getTimeSeriesEnd() this defines the time series time range this index has and the range of timestamps all documents in this index have.
      Returns:
      If this index is in IndexMode.TIME_SERIES then this returns the lower boundary of the time series time range. If this index isn't in IndexMode.TIME_SERIES then null is returned.
    • getTimeSeriesEnd

      @Nullable public Instant getTimeSeriesEnd()
      If this index is in IndexMode.TIME_SERIES then this returns the upper boundary of the time series time range. Together with getTimeSeriesStart() this defines the time series time range this index has and the range of timestamps all documents in this index have.
      Returns:
      If this index is in IndexMode.TIME_SERIES then this returns the upper boundary of the time series time range. If this index isn't in IndexMode.TIME_SERIES then null is returned.
    • mapping

      @Nullable public MappingMetadata mapping()
      Return the concrete mapping for this index or null if this index has no mappings at all.
    • getStats

      @Nullable public IndexMetadataStats getStats()
    • getForecastedWriteLoad

      public OptionalDouble getForecastedWriteLoad()
    • getForecastedShardSizeInBytes

      public OptionalLong getForecastedShardSizeInBytes()
    • getResizeSourceIndex

      public Index getResizeSourceIndex()
    • getCustomData

      public Map<String,String> getCustomData(String key)
    • getInSyncAllocationIds

      public Map<Integer,Set<String>> getInSyncAllocationIds()
    • getRolloverInfos

      public Map<String,RolloverInfo> getRolloverInfos()
    • inSyncAllocationIds

      public Set<String> inSyncAllocationIds(int shardId)
    • requireFilters

      @Nullable public DiscoveryNodeFilters requireFilters()
    • getInitialRecoveryFilters

      @Nullable public DiscoveryNodeFilters getInitialRecoveryFilters()
    • includeFilters

      @Nullable public DiscoveryNodeFilters includeFilters()
    • excludeFilters

      @Nullable public DiscoveryNodeFilters excludeFilters()
    • getTimestampRange

      public IndexLongFieldRange getTimestampRange()
    • getTimeSeriesTimestampRange

      @Nullable public IndexLongFieldRange getTimeSeriesTimestampRange()
      Returns:
      the time range this index represents if this index is in time series mode. Otherwise null is returned.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • diff

      public Diff<IndexMetadata> diff(IndexMetadata previousState)
      Description copied from interface: Diffable
      Returns serializable object representing differences between this and previousState
      Specified by:
      diff in interface Diffable<IndexMetadata>
    • readDiffFrom

      public static Diff<IndexMetadata> readDiffFrom(StreamInput in) throws IOException
      Throws:
      IOException
    • fromXContent

      public static IndexMetadata fromXContent(XContentParser parser) throws IOException
      Throws:
      IOException
    • fromXContent

      public static IndexMetadata fromXContent(XContentParser parser, Map<String,MappingMetadata> mappingsByHash) throws IOException
      Throws:
      IOException
    • toXContent

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

      public static IndexMetadata readFrom(StreamInput in) throws IOException
      Throws:
      IOException
    • readFrom

      public static IndexMetadata readFrom(StreamInput in, @Nullable Function<String,MappingMetadata> mappingLookup) throws IOException
      Parameters:
      mappingLookup - optional lookup function that translates mapping metadata hashes into concrete instances. If specified we assume that the stream contains only mapping metadata hashes but not fully serialized instances of mapping metadata.
      Throws:
      IOException
    • writeTo

      public void writeTo(StreamOutput out, boolean mappingsAsHash) throws IOException
      Parameters:
      mappingsAsHash - whether to serialize MappingMetadata in full or just its hash MappingMetadata.getSha256()
      Throws:
      IOException
    • writeTo

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

      public boolean isSystem()
    • isHidden

      public boolean isHidden()
    • priority

      public int priority()
    • builder

      public static IndexMetadata.Builder builder(String index)
    • builder

      public static IndexMetadata.Builder builder(IndexMetadata indexMetadata)
    • addHumanReadableSettings

      public static Settings addHumanReadableSettings(Settings settings)
      Adds human readable version and creation date settings. This method is used to display the settings in a human readable format in REST API
    • getRoutingNumShards

      public int getRoutingNumShards()
      Returns the number of shards that should be used for routing. This basically defines the hash space we use in IndexRouting.indexShard(java.lang.String, java.lang.String, org.elasticsearch.xcontent.XContentType, org.elasticsearch.common.bytes.BytesReference) to route documents to shards based on their ID or their specific routing value. The default value is getNumberOfShards(). This value only changes if and index is shrunk.
    • getRoutingFactor

      public int getRoutingFactor()
      Returns the routing factor for this index. The default is 1.
      See Also:
    • selectSplitShard

      public static ShardId selectSplitShard(int shardId, IndexMetadata sourceIndexMetadata, int numTargetShards)
      Returns the source shard ID to split the given target shard off
      Parameters:
      shardId - the id of the target shard to split into
      sourceIndexMetadata - the source index metadata
      numTargetShards - the total number of shards in the target index
      Returns:
      a the source shard ID to split off from
    • selectCloneShard

      public static ShardId selectCloneShard(int shardId, IndexMetadata sourceIndexMetadata, int numTargetShards)
      Returns the source shard ID to clone the given target shard off
      Parameters:
      shardId - the id of the target shard to clone into
      sourceIndexMetadata - the source index metadata
      numTargetShards - the total number of shards in the target index
      Returns:
      a the source shard ID to clone from
    • selectRecoverFromShards

      public static Set<ShardId> selectRecoverFromShards(int shardId, IndexMetadata sourceIndexMetadata, int numTargetShards)
      Selects the source shards for a local shard recovery. This might either be a split or a shrink operation.
      Parameters:
      shardId - the target shard ID to select the source shards for
      sourceIndexMetadata - the source metadata
      numTargetShards - the number of target shards
    • selectShrinkShards

      public static Set<ShardId> selectShrinkShards(int shardId, IndexMetadata sourceIndexMetadata, int numTargetShards)
      Returns the source shard ids to shrink into the given shard id.
      Parameters:
      shardId - the id of the target shard to shrink to
      sourceIndexMetadata - the source index metadata
      numTargetShards - the total number of shards in the target index
      Returns:
      a set of shard IDs to shrink into the given shard ID.
    • getRoutingFactor

      public static int getRoutingFactor(int sourceNumberOfShards, int targetNumberOfShards)
      Returns the routing factor for and shrunk index with the given number of target shards. This factor is used in the hash function in IndexRouting.indexShard(java.lang.String, java.lang.String, org.elasticsearch.xcontent.XContentType, org.elasticsearch.common.bytes.BytesReference) to guarantee consistent hashing / routing of documents even if the number of shards changed (ie. a shrunk index).
      Parameters:
      sourceNumberOfShards - the total number of shards in the source index
      targetNumberOfShards - the total number of shards in the target index
      Returns:
      the routing factor for and shrunk index with the given number of target shards.
      Throws:
      IllegalArgumentException - if the number of source shards is less than the number of target shards or if the source shards are not divisible by the number of target shards.
    • parseIndexNameCounter

      public static int parseIndexNameCounter(String indexName)
      Parses the number from the rolled over index name. It also supports the date-math format (ie. index name is wrapped in < and >) E.g. - For ".ds-logs-000002" it will return 2 - For "<logs-{now/d}-3>" it'll return 3
      Throws:
      IllegalArgumentException - if the index doesn't contain a "-" separator or if the last token after the separator is not a number