Class MetadataIndexTemplateService

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

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

  • Constructor Details

  • Method Details

    • removeTemplates

    • putComponentTemplate

      public void putComponentTemplate(String cause, boolean create, String name, org.elasticsearch.core.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(String[] names, org.elasticsearch.core.TimeValue masterTimeout, ClusterState state, 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(String cause, boolean create, String name, org.elasticsearch.core.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, String name, ComposableIndexTemplate template)
    • addIndexTemplateV2

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

      public static Map<String,List<String>> findConflictingV1Templates(ClusterState state, String candidateName, List<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 Map<String,List<String>> findConflictingV2Templates(ClusterState state, String candidateName, List<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(String[] names, org.elasticsearch.core.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 List<IndexTemplateMetadata> findV1Templates(Metadata metadata, String indexName, @Nullable 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 String findV2Template(Metadata metadata, 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 List<CompressedXContent> collectMappings(ClusterState state, String templateName, String indexName) throws Exception
      Collect the given v2 template into an ordered list of mappings.
      Throws:
      Exception
    • collectMappings

      public static List<CompressedXContent> collectMappings(ComposableIndexTemplate template, Map<String,ComponentTemplate> componentTemplates, String indexName) throws Exception
      Collect the given v2 template into an ordered list of mappings.
      Throws:
      Exception
    • resolveSettings

      public static Settings resolveSettings(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, String templateName)
      Resolve the given v2 template into a collected Settings object
    • resolveSettings

      public static Settings resolveSettings(ComposableIndexTemplate template, Map<String,ComponentTemplate> componentTemplates)
      Resolve the provided v2 template and component templates into a collected Settings object
    • resolveAliases

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

      public static List<Map<String,AliasMetadata>> resolveAliases(Metadata metadata, 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.