Class IndexMetaData
- java.lang.Object
-
- org.elasticsearch.cluster.metadata.IndexMetaData
-
- All Implemented Interfaces:
Diffable<IndexMetaData>
,Writeable
,ToXContent
,ToXContentFragment
public class IndexMetaData extends java.lang.Object implements Diffable<IndexMetaData>, ToXContentFragment
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IndexMetaData.Builder
static class
IndexMetaData.State
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Method Summary
Modifier and Type Method Description static Settings
addHumanReadableSettings(Settings settings)
Adds human readable version and creation date settings.static IndexMetaData.Builder
builder(java.lang.String index)
static IndexMetaData.Builder
builder(IndexMetaData indexMetaData)
Diff<IndexMetaData>
diff(IndexMetaData previousState)
Returns serializable object representing differences between this and previousStateboolean
equals(java.lang.Object o)
DiscoveryNodeFilters
excludeFilters()
static IndexMetaData
fromXContent(XContentParser parser)
ImmutableOpenMap<java.lang.String,AliasMetaData>
getAliases()
long
getCreationDate()
Version
getCreationVersion()
Return theVersion
on which this index has been created.java.util.Map<java.lang.String,java.lang.String>
getCustomData(java.lang.String key)
Index
getIndex()
java.lang.String
getIndexUUID()
DiscoveryNodeFilters
getInitialRecoveryFilters()
ImmutableOpenIntMap<java.util.Set<java.lang.String>>
getInSyncAllocationIds()
ImmutableOpenMap<java.lang.String,MappingMetaData>
getMappings()
long
getMappingVersion()
int
getNumberOfReplicas()
int
getNumberOfShards()
Index
getResizeSourceIndex()
ImmutableOpenMap<java.lang.String,RolloverInfo>
getRolloverInfos()
int
getRoutingFactor()
Returns the routing factor for this index.static int
getRoutingFactor(int sourceNumberOfShards, int targetNumberOfShards)
Returns the routing factor for and shrunk index with the given number of target shards.int
getRoutingNumShards()
Returns the number of shards that should be used for routing.int
getRoutingPartitionSize()
Settings
getSettings()
long
getSettingsVersion()
IndexMetaData.State
getState()
int
getTotalNumberOfShards()
Version
getUpgradedVersion()
Return theVersion
on which this index has been upgraded.long
getVersion()
ActiveShardCount
getWaitForActiveShards()
Returns the configuredSETTING_WAIT_FOR_ACTIVE_SHARDS
, which defaults to an active shard count of 1 if not specified.int
hashCode()
DiscoveryNodeFilters
includeFilters()
java.util.Set<java.lang.String>
inSyncAllocationIds(int shardId)
boolean
isRoutingPartitionedIndex()
boolean
isSameUUID(java.lang.String otherUUID)
Test whether the current index UUID is the same as the given one.MappingMetaData
mapping(java.lang.String mappingType)
MappingMetaData
mappingOrDefault(java.lang.String mappingType)
Sometimes, the default mapping exists and an actual mapping is not created yet (introduced), in this case, we want to return the default mapping in case it has some default mapping definitions.long
primaryTerm(int shardId)
The term of the current selected primary.static Diff<IndexMetaData>
readDiffFrom(StreamInput in)
static IndexMetaData
readFrom(StreamInput in)
DiscoveryNodeFilters
requireFilters()
java.lang.String
resolveDocumentType(java.lang.String type)
Resolves a type from a mapping-related request into the type that should be used when merging and updating mappings.static java.util.Set<ShardId>
selectRecoverFromShards(int shardId, IndexMetaData sourceIndexMetadata, int numTargetShards)
Selects the source shards for a local shard recovery.static java.util.Set<ShardId>
selectShrinkShards(int shardId, IndexMetaData sourceIndexMetadata, int numTargetShards)
Returns the source shard ids to shrink into the given shard id.static ShardId
selectSplitShard(int shardId, IndexMetaData sourceIndexMetadata, int numTargetShards)
Returns the source shard ID to split the given target shard offXContentBuilder
toXContent(XContentBuilder builder, ToXContent.Params params)
void
writeTo(StreamOutput out)
Write this into the StreamOutput.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentFragment
isFragment
-
-
-
-
Field Detail
-
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 java.lang.String INDEX_SETTING_PREFIX
- See Also:
- Constant Field Values
-
SETTING_NUMBER_OF_SHARDS
public static final java.lang.String SETTING_NUMBER_OF_SHARDS
- See Also:
- Constant Field Values
-
INDEX_NUMBER_OF_SHARDS_SETTING
public static final Setting<java.lang.Integer> INDEX_NUMBER_OF_SHARDS_SETTING
-
SETTING_NUMBER_OF_REPLICAS
public static final java.lang.String SETTING_NUMBER_OF_REPLICAS
- See Also:
- Constant Field Values
-
INDEX_NUMBER_OF_REPLICAS_SETTING
public static final Setting<java.lang.Integer> INDEX_NUMBER_OF_REPLICAS_SETTING
-
SETTING_ROUTING_PARTITION_SIZE
public static final java.lang.String SETTING_ROUTING_PARTITION_SIZE
- See Also:
- Constant Field Values
-
INDEX_ROUTING_PARTITION_SIZE_SETTING
public static final Setting<java.lang.Integer> INDEX_ROUTING_PARTITION_SIZE_SETTING
-
INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING
public static final Setting<java.lang.Integer> INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING
-
SETTING_AUTO_EXPAND_REPLICAS
public static final java.lang.String SETTING_AUTO_EXPAND_REPLICAS
- See Also:
- Constant Field Values
-
INDEX_AUTO_EXPAND_REPLICAS_SETTING
public static final Setting<AutoExpandReplicas> INDEX_AUTO_EXPAND_REPLICAS_SETTING
-
SETTING_READ_ONLY
public static final java.lang.String SETTING_READ_ONLY
- See Also:
- Constant Field Values
-
INDEX_READ_ONLY_SETTING
public static final Setting<java.lang.Boolean> INDEX_READ_ONLY_SETTING
-
SETTING_BLOCKS_READ
public static final java.lang.String SETTING_BLOCKS_READ
- See Also:
- Constant Field Values
-
INDEX_BLOCKS_READ_SETTING
public static final Setting<java.lang.Boolean> INDEX_BLOCKS_READ_SETTING
-
SETTING_BLOCKS_WRITE
public static final java.lang.String SETTING_BLOCKS_WRITE
- See Also:
- Constant Field Values
-
INDEX_BLOCKS_WRITE_SETTING
public static final Setting<java.lang.Boolean> INDEX_BLOCKS_WRITE_SETTING
-
SETTING_BLOCKS_METADATA
public static final java.lang.String SETTING_BLOCKS_METADATA
- See Also:
- Constant Field Values
-
INDEX_BLOCKS_METADATA_SETTING
public static final Setting<java.lang.Boolean> INDEX_BLOCKS_METADATA_SETTING
-
SETTING_READ_ONLY_ALLOW_DELETE
public static final java.lang.String SETTING_READ_ONLY_ALLOW_DELETE
- See Also:
- Constant Field Values
-
INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING
public static final Setting<java.lang.Boolean> INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING
-
SETTING_VERSION_CREATED
public static final java.lang.String SETTING_VERSION_CREATED
- See Also:
- Constant Field Values
-
SETTING_VERSION_CREATED_STRING
public static final java.lang.String SETTING_VERSION_CREATED_STRING
- See Also:
- Constant Field Values
-
SETTING_VERSION_UPGRADED
public static final java.lang.String SETTING_VERSION_UPGRADED
- See Also:
- Constant Field Values
-
SETTING_VERSION_UPGRADED_STRING
public static final java.lang.String SETTING_VERSION_UPGRADED_STRING
- See Also:
- Constant Field Values
-
SETTING_CREATION_DATE
public static final java.lang.String SETTING_CREATION_DATE
- See Also:
- Constant Field Values
-
SETTING_INDEX_PROVIDED_NAME
public static final java.lang.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:
- Constant Field Values
-
SETTING_PRIORITY
public static final java.lang.String SETTING_PRIORITY
- See Also:
- Constant Field Values
-
INDEX_PRIORITY_SETTING
public static final Setting<java.lang.Integer> INDEX_PRIORITY_SETTING
-
SETTING_CREATION_DATE_STRING
public static final java.lang.String SETTING_CREATION_DATE_STRING
- See Also:
- Constant Field Values
-
SETTING_INDEX_UUID
public static final java.lang.String SETTING_INDEX_UUID
- See Also:
- Constant Field Values
-
SETTING_DATA_PATH
public static final java.lang.String SETTING_DATA_PATH
- See Also:
- Constant Field Values
-
INDEX_DATA_PATH_SETTING
public static final Setting<java.lang.String> INDEX_DATA_PATH_SETTING
-
INDEX_UUID_NA_VALUE
public static final java.lang.String INDEX_UUID_NA_VALUE
- See Also:
- Constant Field Values
-
INDEX_ROUTING_REQUIRE_GROUP_PREFIX
public static final java.lang.String INDEX_ROUTING_REQUIRE_GROUP_PREFIX
- See Also:
- Constant Field Values
-
INDEX_ROUTING_INCLUDE_GROUP_PREFIX
public static final java.lang.String INDEX_ROUTING_INCLUDE_GROUP_PREFIX
- See Also:
- Constant Field Values
-
INDEX_ROUTING_EXCLUDE_GROUP_PREFIX
public static final java.lang.String INDEX_ROUTING_EXCLUDE_GROUP_PREFIX
- See Also:
- Constant Field Values
-
INDEX_ROUTING_REQUIRE_GROUP_SETTING
public static final Setting.AffixSetting<java.lang.String> INDEX_ROUTING_REQUIRE_GROUP_SETTING
-
INDEX_ROUTING_INCLUDE_GROUP_SETTING
public static final Setting.AffixSetting<java.lang.String> INDEX_ROUTING_INCLUDE_GROUP_SETTING
-
INDEX_ROUTING_EXCLUDE_GROUP_SETTING
public static final Setting.AffixSetting<java.lang.String> INDEX_ROUTING_EXCLUDE_GROUP_SETTING
-
INDEX_ROUTING_INITIAL_RECOVERY_GROUP_SETTING
public static final Setting.AffixSetting<java.lang.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.
-
INDEX_FORMAT_SETTING
public static final Setting<java.lang.Integer> INDEX_FORMAT_SETTING
-
KEY_IN_SYNC_ALLOCATIONS
public static final java.lang.String KEY_IN_SYNC_ALLOCATIONS
- See Also:
- Constant Field Values
-
KEY_PRIMARY_TERMS
public static final java.lang.String KEY_PRIMARY_TERMS
- See Also:
- Constant Field Values
-
INDEX_STATE_FILE_PREFIX
public static final java.lang.String INDEX_STATE_FILE_PREFIX
- See Also:
- Constant Field Values
-
INDEX_SHRINK_SOURCE_UUID_KEY
public static final java.lang.String INDEX_SHRINK_SOURCE_UUID_KEY
- See Also:
- Constant Field Values
-
INDEX_SHRINK_SOURCE_NAME_KEY
public static final java.lang.String INDEX_SHRINK_SOURCE_NAME_KEY
- See Also:
- Constant Field Values
-
INDEX_RESIZE_SOURCE_UUID_KEY
public static final java.lang.String INDEX_RESIZE_SOURCE_UUID_KEY
- See Also:
- Constant Field Values
-
INDEX_RESIZE_SOURCE_NAME_KEY
public static final java.lang.String INDEX_RESIZE_SOURCE_NAME_KEY
- See Also:
- Constant Field Values
-
INDEX_SHRINK_SOURCE_UUID
public static final Setting<java.lang.String> INDEX_SHRINK_SOURCE_UUID
-
INDEX_SHRINK_SOURCE_NAME
public static final Setting<java.lang.String> INDEX_SHRINK_SOURCE_NAME
-
INDEX_RESIZE_SOURCE_UUID
public static final Setting<java.lang.String> INDEX_RESIZE_SOURCE_UUID
-
INDEX_RESIZE_SOURCE_NAME
public static final Setting<java.lang.String> INDEX_RESIZE_SOURCE_NAME
-
FORMAT
public static final MetaDataStateFormat<IndexMetaData> FORMAT
State format forIndexMetaData
to write to and load from disk
-
-
Method Detail
-
getIndex
public Index getIndex()
-
getIndexUUID
public java.lang.String getIndexUUID()
-
isSameUUID
public boolean isSameUUID(java.lang.String otherUUID)
Test whether the current index UUID is the same as the given one. Returns true if either are _na_
-
getVersion
public long getVersion()
-
getMappingVersion
public long getMappingVersion()
-
getSettingsVersion
public long getSettingsVersion()
-
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. SeeIndexMetaDataUpdater.applyChanges(org.elasticsearch.cluster.metadata.MetaData, org.elasticsearch.cluster.routing.RoutingTable)
.
-
getCreationVersion
public Version getCreationVersion()
Return theVersion
on which this index has been created. This information is typically useful for backward compatibility.
-
getUpgradedVersion
public Version getUpgradedVersion()
Return theVersion
on which this index has been upgraded. This information is typically useful for backward compatibility.
-
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()
-
getTotalNumberOfShards
public int getTotalNumberOfShards()
-
getWaitForActiveShards
public ActiveShardCount getWaitForActiveShards()
Returns the configuredSETTING_WAIT_FOR_ACTIVE_SHARDS
, which defaults to an active shard count of 1 if not specified.
-
getSettings
public Settings getSettings()
-
getAliases
public ImmutableOpenMap<java.lang.String,AliasMetaData> getAliases()
-
getMappings
public ImmutableOpenMap<java.lang.String,MappingMetaData> getMappings()
-
mapping
@Nullable public MappingMetaData mapping(java.lang.String mappingType)
-
getResizeSourceIndex
public Index getResizeSourceIndex()
-
mappingOrDefault
@Nullable public MappingMetaData mappingOrDefault(java.lang.String mappingType)
Sometimes, the default mapping exists and an actual mapping is not created yet (introduced), in this case, we want to return the default mapping in case it has some default mapping definitions.Note, once the mapping type is introduced, the default mapping is applied on the actual typed MappingMetaData, setting its routing, timestamp, and so on if needed.
-
resolveDocumentType
public java.lang.String resolveDocumentType(java.lang.String type)
Resolves a type from a mapping-related request into the type that should be used when merging and updating mappings. If the special `_doc` type is provided, then we replace it with the actual type that is being used in the mappings. This allows typeless APIs such as 'index' or 'put mappings' to work against indices with a custom type name.
-
getCustomData
public java.util.Map<java.lang.String,java.lang.String> getCustomData(java.lang.String key)
-
getInSyncAllocationIds
public ImmutableOpenIntMap<java.util.Set<java.lang.String>> getInSyncAllocationIds()
-
getRolloverInfos
public ImmutableOpenMap<java.lang.String,RolloverInfo> getRolloverInfos()
-
inSyncAllocationIds
public java.util.Set<java.lang.String> inSyncAllocationIds(int shardId)
-
requireFilters
@Nullable public DiscoveryNodeFilters requireFilters()
-
getInitialRecoveryFilters
@Nullable public DiscoveryNodeFilters getInitialRecoveryFilters()
-
includeFilters
@Nullable public DiscoveryNodeFilters includeFilters()
-
excludeFilters
@Nullable public DiscoveryNodeFilters excludeFilters()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.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 interfaceDiffable<IndexMetaData>
-
readDiffFrom
public static Diff<IndexMetaData> readDiffFrom(StreamInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
fromXContent
public static IndexMetaData fromXContent(XContentParser parser) throws java.io.IOException
- Throws:
java.io.IOException
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
toXContent
in interfaceToXContent
- Throws:
java.io.IOException
-
readFrom
public static IndexMetaData readFrom(StreamInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:Writeable
Write this into the StreamOutput.
-
builder
public static IndexMetaData.Builder builder(java.lang.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 inOperationRouting.generateShardId(IndexMetaData, String, String)
to route documents to shards based on their ID or their specific routing value. The default value isgetNumberOfShards()
. This value only changes if and index is shrunk.
-
getRoutingFactor
public int getRoutingFactor()
Returns the routing factor for this index. The default is1
.- See Also:
for details
-
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 intosourceIndexMetadata
- the source index metadatanumTargetShards
- the total number of shards in the target index- Returns:
- a the source shard ID to split off from
-
selectRecoverFromShards
public static java.util.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 forsourceIndexMetadata
- the source metadatanumTargetShards
- the number of target shards
-
selectShrinkShards
public static java.util.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 tosourceIndexMetadata
- the source index metadatanumTargetShards
- 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 inOperationRouting.generateShardId(IndexMetaData, String, String)
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 indextargetNumberOfShards
- 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:
java.lang.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.
-
-