java.lang.Object
org.elasticsearch.cluster.metadata.Metadata
- All Implemented Interfaces:
Iterable<IndexMetadata>,Diffable<Metadata>,Writeable,ChunkedToXContent
public class Metadata
extends Object
implements Iterable<IndexMetadata>, Diffable<Metadata>, ChunkedToXContent
Metadata is the part of the ClusterState which persists across restarts. This persistence is XContent-based, so a
round-trip through XContent must be faithful in Metadata.XContentContext.GATEWAY context.
The details of how this is persisted are covered in PersistedClusterStateService.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfaceCustom metadata that persists (via XContent) across restarts.static enumNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic EnumSet<Metadata.XContentContext> Indicates that this custom metadata will be returned as part of an API call, stored as a part of a snapshot global state, and will be persisted between node restartsstatic EnumSet<Metadata.XContentContext> Indicates that this custom metadata will be returned as part of an API call and will be persisted between node restarts, but will not be a part of a snapshot global statestatic EnumSet<Metadata.XContentContext> Indicates that this custom metadata will be returned as part of an API call and stored as a part of a snapshot global state, but will not be persisted between node restartsstatic EnumSet<Metadata.XContentContext> Indicates that this custom metadata will be returned as part of an API call but will not be persistedstatic final ClusterBlockstatic final ClusterBlockstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Metadatastatic final MetadataStateFormat<Metadata> State format forMetadatato write to and load from diskstatic final Stringstatic final TransportVersionstatic final Runnablestatic final StringFields inherited from interface org.elasticsearch.common.xcontent.ChunkedToXContent
EMPTY -
Method Summary
Modifier and TypeMethodDescriptionaliasedIndices(String aliasName) Returns all the indices that the alias with the provided alias name refers to.static Metadata.Builderbuilder()static Metadata.BuilderbooleanWhether the current node with the given cluster state is locked into the cluster with the UUID returned byclusterUUID(), meaning that it will not accept any cluster state with a different clusterUUID.copyAndUpdate(Consumer<Metadata.Builder> updater) <T extends Metadata.Custom>
T<T extends Metadata.Custom>
Tcustoms()Return a map of DataStreamAlias objects by DataStream nameReturns serializable object representing differences between this and previousStatebooleanequalsAliases(Metadata other) findAliases(String[] aliases, String[] concreteIndices) Finds the specific index aliases that match with the specified aliases directly or partially via wildcards, and that point to the specified concrete indices (directly or matching indices via wildcards).findAllAliases(String[] concreteIndices) Finds the specific index aliases that point to the requested concrete indices directly or that match with the indices via wildcards.findDataStreamAliases(String[] aliases, String[] dataStreams) Finds the specific data stream aliases that match with the specified aliases directly or partially via wildcards, and that point to the specified data streams (directly or matching data streams via wildcards).findDataStreams(String... concreteIndices) Finds the parent data streams, if any, for the specified concrete indices.findMappings(String[] concreteIndices, Function<String, ? extends Predicate<String>> fieldFilter, Runnable onNextIndex) Finds all mappings for concrete indices.static MetadatafromXContent(XContentParser parser) String[]Returns all of the concrete indices that are closed.String[]Returns all the concrete indices.String[]Returns all of the concrete indices that are open.String[]Returns all of the concrete indices that are closed and not hidden.String[]Returns all the concrete indices that are not hidden.String[]Returns all of the concrete indices that are open and not hidden.getIndexSafe(Index index) Returns theIndexMetadatafor this index.intGets the total number of shards from all indices, including replicas and closed indices.intGets the total number of open shards from all indices.booleanReturns whether an alias exists with provided alias name.booleanChecks whether an index exists (as of thisMetadatawith the given name.booleanChecks whether an index exists.booleanhasIndexAbstraction(String index) Checks whether an index abstraction (that is, index, alias, or data stream) exists (as of thisMetadatawith the given name.booleanhasIndexMetadata(IndexMetadata indexMetadata) Returns true iff existing index has the sameIndexMetadatainstanceThe collection of index deletions in the cluster.booleanindexIsADataStream(String indexName) Checks whether the provided index is a data stream.indices()booleanstatic booleanisGlobalStateEquals(Metadata metadata1, Metadata metadata2) booleanisIndexManagedByILM(IndexMetadata indexMetadata) Indicates if the provided index is managed by ILM.iterator()static MetadatareadFrom(StreamInput in) Returns the fullReservedStateMetadataMap for all reserved state namespaces.resolveIndexRouting(String routing, String aliasOrIndex) Returns indexing routing for the given index.resolveWriteIndexRouting(String routing, String aliasOrIndex) Returns indexing routing for the givenaliasOrIndex.retrieveIndexModeFromTemplate(ComposableIndexTemplate indexTemplate) booleansameIndicesLookup(Metadata other) settings()Returns the merged transient and persistent settings.intsize()stream()Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) Create an iterator ofToXContentchunks for a REST response.longversion()withAddedIndex(IndexMetadata index) Creates a copy of this instance with the givenindexadded.Creates a copy of this instance updated with the givenIndexMetadatathat must only contain changes to primary terms and in-sync allocation ids relative to the existing entries.withCoordinationMetadata(CoordinationMetadata coordinationMetadata) withIndexSettingsUpdates(Map<Index, Settings> updates) withLastCommittedValues(boolean clusterUUIDCommitted, CoordinationMetadata.VotingConfiguration lastCommittedConfiguration) withLifecycleState(Index index, LifecycleExecutionState lifecycleState) Given an index and lifecycle state, returns a metadata where the lifecycle state will be associated with the given index.voidwriteTo(StreamOutput out) Write this into the StreamOutput.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.elasticsearch.common.xcontent.ChunkedToXContent
isFragment, toXContentChunkedV7Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
ON_NEXT_INDEX_FIND_MAPPINGS_NOOP
-
ALL
- See Also:
-
UNKNOWN_CLUSTER_UUID
- See Also:
-
API_ONLY
Indicates that this custom metadata will be returned as part of an API call but will not be persisted -
API_AND_GATEWAY
Indicates that this custom metadata will be returned as part of an API call and will be persisted between node restarts, but will not be a part of a snapshot global state -
API_AND_SNAPSHOT
Indicates that this custom metadata will be returned as part of an API call and stored as a part of a snapshot global state, but will not be persisted between node restarts -
ALL_CONTEXTS
Indicates that this custom metadata will be returned as part of an API call, stored as a part of a snapshot global state, and will be persisted between node restarts -
SETTING_READ_ONLY_SETTING
-
CLUSTER_READ_ONLY_BLOCK
-
SETTING_READ_ONLY_ALLOW_DELETE_SETTING
-
CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK
-
EMPTY_METADATA
-
CONTEXT_MODE_PARAM
- See Also:
-
CONTEXT_MODE_SNAPSHOT
-
CONTEXT_MODE_GATEWAY
-
CONTEXT_MODE_API
-
DEDUPLICATED_MAPPINGS_PARAM
- See Also:
-
GLOBAL_STATE_FILE_PREFIX
- See Also:
-
MAPPINGS_AS_HASH_VERSION
-
FORMAT
State format forMetadatato write to and load from disk
-
-
Method Details
-
withIncrementedVersion
-
withLifecycleState
Given an index and lifecycle state, returns a metadata where the lifecycle state will be associated with the given index. The passed-in index must already be present in the cluster state, this method cannot be used to add an index.- Parameters:
index- A non-null indexlifecycleState- A non-null lifecycle execution state- Returns:
- a
Metadatainstance where the index has the provided lifecycle state
-
withIndexSettingsUpdates
-
withCoordinationMetadata
-
withLastCommittedValues
public Metadata withLastCommittedValues(boolean clusterUUIDCommitted, CoordinationMetadata.VotingConfiguration lastCommittedConfiguration) -
withAllocationAndTermUpdatesOnly
Creates a copy of this instance updated with the givenIndexMetadatathat must only contain changes to primary terms and in-sync allocation ids relative to the existing entries. This method is only used byIndexMetadataUpdater.applyChanges(Metadata, RoutingTable, TransportVersion).- Parameters:
updates- map of index name toIndexMetadata.- Returns:
- updated metadata instance
-
withAddedIndex
Creates a copy of this instance with the givenindexadded.- Parameters:
index- index to add- Returns:
- copy with added index
-
version
public long version() -
clusterUUID
- Returns:
- A UUID which identifies this cluster. Nodes record the UUID of the cluster they first join on disk, and will then refuse to
join clusters with different UUIDs. Note that when the cluster is forming for the first time this value may not yet be committed,
and therefore it may change. Check
clusterUUIDCommitted()to verify that the value is committed if needed.
-
clusterUUIDCommitted
public boolean clusterUUIDCommitted()Whether the current node with the given cluster state is locked into the cluster with the UUID returned byclusterUUID(), meaning that it will not accept any cluster state with a different clusterUUID. -
settings
Returns the merged transient and persistent settings. -
transientSettings
-
persistentSettings
-
hashesOfConsistentSettings
-
coordinationMetadata
-
oldestIndexVersion
-
equalsAliases
-
indicesLookupInitialized
public boolean indicesLookupInitialized() -
getIndicesLookup
-
sameIndicesLookup
-
findAllAliases
Finds the specific index aliases that point to the requested concrete indices directly or that match with the indices via wildcards.- Parameters:
concreteIndices- The concrete indices that the aliases must point to in order to be returned.- Returns:
- A map of index name to the list of aliases metadata. If a concrete index does not have matching aliases then the result will not include the index's key.
-
findAliases
Finds the specific index aliases that match with the specified aliases directly or partially via wildcards, and that point to the specified concrete indices (directly or matching indices via wildcards).- Parameters:
aliases- The aliases to look for. Might contain include or exclude wildcards.concreteIndices- The concrete indices that the aliases must point to in order to be returned- Returns:
- A map of index name to the list of aliases metadata. If a concrete index does not have matching aliases then the result will not include the index's key.
-
findDataStreamAliases
public Map<String,List<DataStreamAlias>> findDataStreamAliases(String[] aliases, String[] dataStreams) Finds the specific data stream aliases that match with the specified aliases directly or partially via wildcards, and that point to the specified data streams (directly or matching data streams via wildcards).- Parameters:
aliases- The aliases to look for. Might contain include or exclude wildcards.dataStreams- The data streams that the aliases must point to in order to be returned- Returns:
- A map of data stream name to the list of DataStreamAlias objects that match. If a data stream does not have matching aliases then the result will not include the data stream's key.
-
findMappings
public Map<String,MappingMetadata> findMappings(String[] concreteIndices, Function<String, ? extends Predicate<String>> fieldFilter, Runnable onNextIndex) Finds all mappings for concrete indices. Only fields that match the provided field filter will be returned (default is a predicate that always returns true, which can be overridden via plugins)- Parameters:
onNextIndex- a hook that gets notified for each index that's processed- See Also:
-
findDataStreams
Finds the parent data streams, if any, for the specified concrete indices. -
indexIsADataStream
Checks whether the provided index is a data stream. -
getConcreteAllIndices
Returns all the concrete indices. -
getConcreteVisibleIndices
Returns all the concrete indices that are not hidden. -
getConcreteAllOpenIndices
Returns all of the concrete indices that are open. -
getConcreteVisibleOpenIndices
Returns all of the concrete indices that are open and not hidden. -
getConcreteAllClosedIndices
Returns all of the concrete indices that are closed. -
getConcreteVisibleClosedIndices
Returns all of the concrete indices that are closed and not hidden. -
resolveWriteIndexRouting
Returns indexing routing for the givenaliasOrIndex. Resolves routing from the alias metadata used in the write index. -
resolveIndexRouting
Returns indexing routing for the given index. -
hasIndex
Checks whether an index exists (as of thisMetadatawith the given name. Does not check aliases or data streams.- Parameters:
index- An index name that may or may not exist in the cluster.- Returns:
trueif a concrete index with that name exists,falseotherwise.
-
hasIndex
Checks whether an index exists. Similar tohasIndex(String), but ensures that the index has the same UUID as the givenIndex.- Parameters:
index- AnIndexobject that may or may not exist in the cluster.- Returns:
trueif an index exists with the same name and UUID as the given index object,falseotherwise.
-
hasIndexAbstraction
Checks whether an index abstraction (that is, index, alias, or data stream) exists (as of thisMetadatawith the given name.- Parameters:
index- An index name that may or may not exist in the cluster.- Returns:
trueif an index abstraction with that name exists,falseotherwise.
-
index
-
index
-
hasIndexMetadata
Returns true iff existing index has the sameIndexMetadatainstance -
getIndexSafe
Returns theIndexMetadatafor this index.- Throws:
IndexNotFoundException- if no metadata for this index is found
-
indices
-
getIndices
-
hasAlias
Returns whether an alias exists with provided alias name.- Parameters:
aliasName- The provided alias name- Returns:
- whether an alias exists with provided alias name
-
aliasedIndices
Returns all the indices that the alias with the provided alias name refers to. These are aliased indices. Not that, this only return indices that have been aliased and not indices that are behind a data stream or data stream alias.- Parameters:
aliasName- The provided alias name- Returns:
- all aliased indices by the alias with the provided alias name
-
aliasedIndices
- Returns:
- the names of all indices aliases.
-
templates
-
getTemplates
-
componentTemplates
-
templatesV2
-
retrieveIndexModeFromTemplate
-
dataStreams
-
dataStreamAliases
-
dataStreamAliasesByDataStream
Return a map of DataStreamAlias objects by DataStream name- Returns:
- a map of DataStreamAlias objects by DataStream name
-
nodeShutdowns
-
isIndexManagedByILM
Indicates if the provided index is managed by ILM. This takes into account if the index is part of data stream that's potentially managed by data stream lifecycle and the value of theIndexSettings.PREFER_ILM_SETTING -
customs
-
reservedStateMetadata
Returns the fullReservedStateMetadataMap for all reserved state namespaces.- Returns:
- a map of namespace to
ReservedStateMetadata
-
indexGraveyard
The collection of index deletions in the cluster. -
custom
-
custom
-
getTotalNumberOfShards
public int getTotalNumberOfShards()Gets the total number of shards from all indices, including replicas and closed indices.- Returns:
- The total number shards from all indices.
-
getTotalOpenIndexShards
public int getTotalOpenIndexShards()Gets the total number of open shards from all indices. Includes replicas, but does not include shards that are part of closed indices.- Returns:
- The total number of open shards from all indices.
-
iterator
- Specified by:
iteratorin interfaceIterable<IndexMetadata>
-
stream
-
size
public int size() -
isGlobalStateEquals
-
diff
Description copied from interface:DiffableReturns serializable object representing differences between this and previousState -
readDiffFrom
- Throws:
IOException
-
fromXContent
- Throws:
IOException
-
toXContentChunked
Description copied from interface:ChunkedToXContentCreate an iterator ofToXContentchunks for a REST response. Each chunk is serialized with the sameXContentBuilderandToXContent.Params, which is also the same as theToXContent.Paramspassed as theparamsargument. For best results, all chunks should beO(1)size. The last chunk in the iterator must always yield at least one byte of output. See alsoChunkedToXContentHelperfor some handy utilities.Note that chunked response bodies cannot send deprecation warning headers once transmission has started, so implementations must check for deprecated feature use before returning.
- Specified by:
toXContentChunkedin interfaceChunkedToXContent- Returns:
- iterator over chunks of
ToXContent
-
getMappingsByHash
-
readFrom
- Throws:
IOException
-
writeTo
Description copied from interface:WriteableWrite this into the StreamOutput.- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
builder
-
builder
-
copyAndUpdate
-