Class MetadataIndexTemplateService
java.lang.Object
org.elasticsearch.cluster.metadata.MetadataIndexTemplateService
Service responsible for submitting index templates updates
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static class
static class
static interface
static class
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMetadataIndexTemplateService(ClusterService clusterService, MetadataCreateIndexService metadataCreateIndexService, AliasValidator aliasValidator, IndicesService indicesService, IndexScopedSettings indexScopedSettings, org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry)
-
Method Summary
Modifier and TypeMethodDescriptionaddIndexTemplateV2(ClusterState currentState, boolean create, String name, ComposableIndexTemplate template)
static List<CompressedXContent>
collectMappings(ClusterState state, String templateName, String indexName)
Collect the given v2 template into an ordered list of mappings.static List<CompressedXContent>
collectMappings(ComposableIndexTemplate template, Map<String,ComponentTemplate> componentTemplates, String indexName)
Collect the given v2 template into an ordered list of mappings.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(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.static List<IndexTemplateMetadata>
findV1Templates(Metadata metadata, String indexName, Boolean isHidden)
Finds index templates whose index pattern matched with the given index name.static String
findV2Template(Metadata metadata, String indexName, boolean isHidden)
Return the name (id) of the highest matching index template for the given index name.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.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.void
putTemplate(MetadataIndexTemplateService.PutRequest request, MetadataIndexTemplateService.PutListener listener)
void
removeComponentTemplate(String[] names, org.elasticsearch.core.TimeValue masterTimeout, ClusterState state, ActionListener<AcknowledgedResponse> listener)
Remove the given component template from the cluster state.void
removeIndexTemplateV2(String[] names, org.elasticsearch.core.TimeValue masterTimeout, ActionListener<AcknowledgedResponse> listener)
Remove the given index template from the cluster state.void
removeTemplates(MetadataIndexTemplateService.RemoveRequest request, MetadataIndexTemplateService.RemoveListener listener)
static List<Map<String,AliasMetadata>>
resolveAliases(List<IndexTemplateMetadata> templates)
Resolve the given v1 templates into an ordered list of aliasesstatic List<Map<String,AliasMetadata>>
resolveAliases(Metadata metadata, String templateName, boolean failIfTemplateHasDataStream)
Resolve the given v2 template into an ordered list of aliasesstatic 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/orderstatic Settings
resolveSettings(ComposableIndexTemplate template, Map<String,ComponentTemplate> componentTemplates)
Resolve the provided v2 template and component templates into a collectedSettings
objectstatic Settings
resolveSettings(Metadata metadata, String templateName)
Resolve the given v2 template into a collectedSettings
objectstatic void
validateV2TemplateRequest(Metadata metadata, String name, ComposableIndexTemplate template)
-
Field Details
-
DEFAULT_TIMESTAMP_FIELD
- See Also:
- Constant Field Values
-
DEFAULT_TIMESTAMP_MAPPING
- See Also:
- Constant Field Values
-
-
Constructor Details
-
MetadataIndexTemplateService
@Inject public MetadataIndexTemplateService(ClusterService clusterService, MetadataCreateIndexService metadataCreateIndexService, AliasValidator aliasValidator, IndicesService indicesService, IndexScopedSettings indexScopedSettings, org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry)
-
-
Method Details
-
removeTemplates
public void removeTemplates(MetadataIndexTemplateService.RemoveRequest request, MetadataIndexTemplateService.RemoveListener listener) -
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. Ifcreate
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. Ifcreate
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
public void putTemplate(MetadataIndexTemplateService.PutRequest request, MetadataIndexTemplateService.PutListener listener) -
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
- TheMetadata
containing all of theIndexTemplateMetadata
valuesindexName
- The name of the index that templates are being found forisHidden
- Whether or not the index is known to be hidden. May benull
if the index being hidden has not been explicitly requested. Whennull
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 ExceptionCollect 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 ExceptionCollect the given v2 template into an ordered list of mappings.- Throws:
Exception
-
resolveSettings
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
Resolve the given v2 template into a collectedSettings
object -
resolveSettings
public static Settings resolveSettings(ComposableIndexTemplate template, Map<String,ComponentTemplate> componentTemplates)Resolve the provided v2 template and component templates into a collectedSettings
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.
-