Class Metadata

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

public class Metadata extends Object implements Iterable<IndexMetadata>, Diffable<Metadata>, org.elasticsearch.common.xcontent.ToXContentFragment
  • Field Details

    • ON_NEXT_INDEX_FIND_MAPPINGS_NOOP

      public static final Runnable ON_NEXT_INDEX_FIND_MAPPINGS_NOOP
    • ALL

      public static final String ALL
      See Also:
      Constant Field Values
    • UNKNOWN_CLUSTER_UUID

      public static final String UNKNOWN_CLUSTER_UUID
      See Also:
      Constant Field Values
    • API_ONLY

      public static EnumSet<Metadata.XContentContext> API_ONLY
      Indicates that this custom metadata will be returned as part of an API call but will not be persisted
    • API_AND_GATEWAY

      public static EnumSet<Metadata.XContentContext> 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

      public static EnumSet<Metadata.XContentContext> 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

      public static EnumSet<Metadata.XContentContext> 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

      public static final Setting<Boolean> SETTING_READ_ONLY_SETTING
    • CLUSTER_READ_ONLY_BLOCK

      public static final ClusterBlock CLUSTER_READ_ONLY_BLOCK
    • SETTING_READ_ONLY_ALLOW_DELETE_SETTING

      public static final Setting<Boolean> SETTING_READ_ONLY_ALLOW_DELETE_SETTING
    • CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK

      public static final ClusterBlock CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK
    • EMPTY_METADATA

      public static final Metadata EMPTY_METADATA
    • CONTEXT_MODE_PARAM

      public static final String CONTEXT_MODE_PARAM
      See Also:
      Constant Field Values
    • CONTEXT_MODE_SNAPSHOT

      public static final String CONTEXT_MODE_SNAPSHOT
    • CONTEXT_MODE_GATEWAY

      public static final String CONTEXT_MODE_GATEWAY
    • CONTEXT_MODE_API

      public static final String CONTEXT_MODE_API
    • GLOBAL_STATE_FILE_PREFIX

      public static final String GLOBAL_STATE_FILE_PREFIX
      See Also:
      Constant Field Values
    • FORMAT

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

    • version

      public long version()
    • clusterUUID

      public String clusterUUID()
    • clusterUUIDCommitted

      public boolean clusterUUIDCommitted()
      Whether the current node with the given cluster state is locked into the cluster with the UUID returned by clusterUUID(), meaning that it will not accept any cluster state with a different clusterUUID.
    • settings

      public Settings settings()
      Returns the merged transient and persistent settings.
    • transientSettings

      public Settings transientSettings()
    • persistentSettings

      public Settings persistentSettings()
    • hashesOfConsistentSettings

      public Map<String,String> hashesOfConsistentSettings()
    • coordinationMetadata

      public CoordinationMetadata coordinationMetadata()
    • hasAlias

      public boolean hasAlias(String alias)
    • equalsAliases

      public boolean equalsAliases(Metadata other)
    • getIndicesLookup

      public SortedMap<String,IndexAbstraction> getIndicesLookup()
    • findAllAliases

      public ImmutableOpenMap<String,List<AliasMetadata>> findAllAliases(String[] concreteIndices)
      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

      public ImmutableOpenMap<String,List<AliasMetadata>> findAliases(AliasesRequest aliasesRequest, 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).
      Parameters:
      aliasesRequest - The request to find aliases for
      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.
    • hasAliases

      public boolean hasAliases(String[] aliases, String[] concreteIndices)
      Checks if at least one of the specified aliases exists in the specified concrete indices. Wildcards are supported in the alias names for partial matches.
      Parameters:
      aliases - The names of the index aliases to find
      concreteIndices - The concrete indexes the index aliases must point to order to be returned.
      Returns:
      whether at least one of the specified aliases exists in one of the specified concrete indices.
    • findMappings

      public ImmutableOpenMap<String,ImmutableOpenMap<String,MappingMetadata>> findMappings(String[] concreteIndices, String[] types, Function<String,Predicate<String>> fieldFilter, Runnable onNextIndex) throws IOException
      Finds all mappings for types and concrete indices. Types are expanded to include all types that match the glob patterns in the types array. Empty types array, null or {"_all"} will be expanded to all types available for the given 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
      Throws:
      IOException
      See Also:
      MapperPlugin.getFieldFilter()
    • findDataStreams

      public ImmutableOpenMap<String,IndexAbstraction.DataStream> findDataStreams(String[] concreteIndices)
      Finds the parent data streams, if any, for the specified concrete indices.
    • getConcreteAllIndices

      public String[] getConcreteAllIndices()
      Returns all the concrete indices.
    • getConcreteVisibleIndices

      public String[] getConcreteVisibleIndices()
      Returns all the concrete indices that are not hidden.
    • getConcreteAllOpenIndices

      public String[] getConcreteAllOpenIndices()
      Returns all of the concrete indices that are open.
    • getConcreteVisibleOpenIndices

      public String[] getConcreteVisibleOpenIndices()
      Returns all of the concrete indices that are open and not hidden.
    • getConcreteAllClosedIndices

      public String[] getConcreteAllClosedIndices()
      Returns all of the concrete indices that are closed.
    • getConcreteVisibleClosedIndices

      public String[] getConcreteVisibleClosedIndices()
      Returns all of the concrete indices that are closed and not hidden.
    • resolveWriteIndexRouting

      public String resolveWriteIndexRouting(@Nullable String routing, String aliasOrIndex)
      Returns indexing routing for the given aliasOrIndex. Resolves routing from the alias metadata used in the write index.
    • resolveIndexRouting

      public String resolveIndexRouting(@Nullable String routing, String aliasOrIndex)
      Returns indexing routing for the given index.
    • hasIndex

      public boolean hasIndex(String index)
    • hasIndex

      public boolean hasIndex(Index index)
    • hasConcreteIndex

      public boolean hasConcreteIndex(String index)
    • index

      public IndexMetadata index(String index)
    • index

      public IndexMetadata index(Index index)
    • hasIndexMetadata

      public boolean hasIndexMetadata(IndexMetadata indexMetadata)
      Returns true iff existing index has the same IndexMetadata instance
    • getIndexSafe

      public IndexMetadata getIndexSafe(Index index)
      Returns the IndexMetadata for this index.
      Throws:
      IndexNotFoundException - if no metadata for this index is found
    • indices

    • getIndices

      public ImmutableOpenMap<String,IndexMetadata> getIndices()
    • templates

    • getTemplates

    • componentTemplates

      public Map<String,ComponentTemplate> componentTemplates()
    • templatesV2

      public Map<String,ComposableIndexTemplate> templatesV2()
    • dataStreams

      public Map<String,DataStream> dataStreams()
    • dataStreamAliases

      public Map<String,DataStreamAlias> dataStreamAliases()
    • customs

    • getCustoms

      public ImmutableOpenMap<String,Metadata.Custom> getCustoms()
    • indexGraveyard

      public IndexGraveyard indexGraveyard()
      The collection of index deletions in the cluster.
    • custom

      public <T extends Metadata.Custom> T custom(String type)
    • custom

      public <T extends Metadata.Custom> T custom(String type, T defaultValue)
    • 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.
    • isAllTypes

      public static boolean isAllTypes(String[] types)
      Identifies whether the array containing type names given as argument refers to all types The empty or null array identifies all types
      Parameters:
      types - the array containing types
      Returns:
      true if the provided array maps to all types, false otherwise
    • isExplicitAllType

      public static boolean isExplicitAllType(String[] types)
      Identifies whether the array containing type names given as argument explicitly refers to all types The empty or null array doesn't explicitly map to all types
      Parameters:
      types - the array containing index names
      Returns:
      true if the provided array explicitly maps to all types, false otherwise
    • routingRequired

      public boolean routingRequired(String concreteIndex)
      Parameters:
      concreteIndex - The concrete index to check if routing is required
      Returns:
      Whether routing is required according to the mapping for the specified index and type
    • iterator

      public Iterator<IndexMetadata> iterator()
      Specified by:
      iterator in interface Iterable<IndexMetadata>
    • isGlobalStateEquals

      public static boolean isGlobalStateEquals(Metadata metadata1, Metadata metadata2)
    • snapshot

      public static Metadata snapshot(Metadata metadata, List<String> dataStreams, List<String> indices)
      Reconciles the cluster state metadata taken at the end of a snapshot with the data streams and indices contained in the snapshot. Certain actions taken during a snapshot such as rolling over a data stream or deleting a backing index may result in situations where some reconciliation is required.
      Returns:
      Reconciled Metadata instance
    • diff

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

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

      public static Metadata fromXContent(org.elasticsearch.common.xcontent.XContentParser parser) throws IOException
      Throws:
      IOException
    • toXContent

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

      public static Metadata readFrom(StreamInput in) throws IOException
      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
    • builder

      public static Metadata.Builder builder()
    • builder

      public static Metadata.Builder builder(Metadata metadata)