Class MetadataIndexTemplateService

java.lang.Object
org.elasticsearch.cluster.metadata.MetadataIndexTemplateService

public class MetadataIndexTemplateService
extends java.lang.Object
Service responsible for submitting index templates updates
  • Field Details

    • DEFAULT_TIMESTAMP_FIELD

      public static final java.lang.String DEFAULT_TIMESTAMP_FIELD
      See Also:
      Constant Field Values
    • DEFAULT_TIMESTAMP_MAPPING

      public static final java.lang.String DEFAULT_TIMESTAMP_MAPPING
      See Also:
      Constant Field Values
  • Constructor Details

  • Method Details

    • removeTemplates

    • putComponentTemplate

      public void putComponentTemplate​(java.lang.String cause, boolean create, java.lang.String name, org.elasticsearch.common.unit.TimeValue masterTimeout, ComponentTemplate template, ActionListener<AcknowledgedResponse> listener)
      Add the given component template to the cluster state. If create is true, an exception will be thrown if the component template already exists
    • removeComponentTemplate

      public void removeComponentTemplate​(java.lang.String name, org.elasticsearch.common.unit.TimeValue masterTimeout, ActionListener<AcknowledgedResponse> listener)
      Remove the given component template from the cluster state. The component template name supports simple regex wildcards for removing multiple component templates at a time.
    • putIndexTemplateV2

      public void putIndexTemplateV2​(java.lang.String cause, boolean create, java.lang.String name, org.elasticsearch.common.unit.TimeValue masterTimeout, ComposableIndexTemplate template, ActionListener<AcknowledgedResponse> listener)
      Add the given index template to the cluster state. If create is true, an exception will be thrown if the component template already exists
    • validateV2TemplateRequest

      public static void validateV2TemplateRequest​(Metadata metadata, java.lang.String name, ComposableIndexTemplate template)
    • addIndexTemplateV2

      public ClusterState addIndexTemplateV2​(ClusterState currentState, boolean create, java.lang.String name, ComposableIndexTemplate template) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • findConflictingV1Templates

      public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> findConflictingV1Templates​(ClusterState state, java.lang.String candidateName, java.util.List<java.lang.String> indexPatterns)
      Return a map of v1 template names to their index patterns for v1 templates that would overlap with the given v2 template's index patterns.
    • findConflictingV2Templates

      public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> findConflictingV2Templates​(ClusterState state, java.lang.String candidateName, java.util.List<java.lang.String> indexPatterns)
      Return a map of v2 template names to their index patterns for v2 templates that would overlap with the given template's index patterns.
    • removeIndexTemplateV2

      public void removeIndexTemplateV2​(java.lang.String name, org.elasticsearch.common.unit.TimeValue masterTimeout, ActionListener<AcknowledgedResponse> listener)
      Remove the given index template from the cluster state. The index template name supports simple regex wildcards for removing multiple index templates at a time.
    • putTemplate

    • findV1Templates

      public static java.util.List<IndexTemplateMetadata> findV1Templates​(Metadata metadata, java.lang.String indexName, @Nullable java.lang.Boolean isHidden)
      Finds index templates whose index pattern matched with the given index name. In the case of hidden indices, a template with a match all pattern or global template will not be returned.
      Parameters:
      metadata - The Metadata containing all of the IndexTemplateMetadata values
      indexName - The name of the index that templates are being found for
      isHidden - Whether or not the index is known to be hidden. May be null if the index being hidden has not been explicitly requested. When null if the result of template application results in a hidden index, then global templates will not be returned
      Returns:
      a list of templates sorted by IndexTemplateMetadata.order() descending.
    • findV2Template

      @Nullable public static java.lang.String findV2Template​(Metadata metadata, java.lang.String indexName, boolean isHidden)
      Return the name (id) of the highest matching index template for the given index name. In the event that no templates are matched, null is returned.
    • collectMappings

      public static java.util.List<CompressedXContent> collectMappings​(ClusterState state, java.lang.String templateName, java.lang.String indexName) throws java.lang.Exception
      Collect the given v2 template into an ordered list of mappings.
      Throws:
      java.lang.Exception
    • resolveSettings

      public static Settings resolveSettings​(java.util.List<IndexTemplateMetadata> templates)
      Resolve index settings for the given list of v1 templates, templates are apply in reverse order since they should be provided in order of priority/order
    • resolveSettings

      public static Settings resolveSettings​(Metadata metadata, java.lang.String templateName)
      Resolve the given v2 template into a collected Settings object
    • resolveAliases

      public static java.util.List<java.util.Map<java.lang.String,​AliasMetadata>> resolveAliases​(java.util.List<IndexTemplateMetadata> templates)
      Resolve the given v1 templates into an ordered list of aliases
    • resolveAliases

      public static java.util.List<java.util.Map<java.lang.String,​AliasMetadata>> resolveAliases​(Metadata metadata, java.lang.String templateName, boolean failIfTemplateHasDataStream)
      Resolve the given v2 template into an ordered list of aliases
      Parameters:
      failIfTemplateHasDataStream - Whether to skip validating if a template has a data stream definition and an alias definition. This validation is needed so that no template gets created that creates datastream and also a an alias pointing to the backing indices of a data stream. Unfortunately this validation was missing in versions prior to 7.11, which mean that there are cluster states out there, that have this malformed templates. This method is used when rolling over a data stream or creating new data streams. In order for these clusters to avoid failing these operations immediately after an upgrade the failure should be optional. So that there is time to change these templates. The logic that adds/updates index and component templates shouldn't skip this validation.