Module org.elasticsearch.server
Class MetadataIndexTemplateService
java.lang.Object
org.elasticsearch.cluster.metadata.MetadataIndexTemplateService
Service responsible for submitting index templates updates
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMetadataIndexTemplateService
(ClusterService clusterService, MetadataCreateIndexService metadataCreateIndexService, IndicesService indicesService, IndexScopedSettings indexScopedSettings, NamedXContentRegistry xContentRegistry, SystemIndices systemIndices, IndexSettingProviders indexSettingProviders) -
Method Summary
Modifier and TypeMethodDescriptionaddComponentTemplate
(ClusterState currentState, boolean create, String name, ComponentTemplate template) addIndexTemplateV2
(ClusterState currentState, boolean create, String name, ComposableIndexTemplate template) addIndexTemplateV2
(ClusterState currentState, boolean create, String name, ComposableIndexTemplate template, boolean validateV2Overlaps) 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.static DataStreamLifecycle
composeDataLifecycles
(List<DataStreamLifecycle> lifecycles) This method composes a series of lifecycles to a final one.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.static ClusterState
innerRemoveComponentTemplate
(ClusterState currentState, String... names) static ClusterState
innerRemoveIndexTemplateV2
(ClusterState currentState, String... names) void
putComponentTemplate
(String cause, boolean create, String name, TimeValue masterTimeout, ComponentTemplate template, ActionListener<AcknowledgedResponse> listener) Add the given component template to the cluster state.void
putIndexTemplateV2
(String cause, boolean create, String name, TimeValue masterTimeout, ComposableIndexTemplate template, ActionListener<AcknowledgedResponse> listener) Add the given index template to the cluster state.void
putTemplate
(MetadataIndexTemplateService.PutRequest request, ActionListener<AcknowledgedResponse> listener) void
removeComponentTemplate
(String[] names, TimeValue masterTimeout, ClusterState state, ActionListener<AcknowledgedResponse> listener) Remove the given component template from the cluster state.void
removeIndexTemplateV2
(String[] names, TimeValue masterTimeout, ActionListener<AcknowledgedResponse> listener) Remove the given index template from the cluster state.void
removeTemplates
(MetadataIndexTemplateService.RemoveRequest request, ActionListener<AcknowledgedResponse> 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) Resolve the given v2 template name into an ordered list of aliasesstatic DataStreamLifecycle
resolveLifecycle
(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates) Resolve the provided v2 template and component templates into aDataStreamLifecycle
objectstatic DataStreamLifecycle
resolveLifecycle
(Metadata metadata, String templateName) Resolve the given v2 template into aDataStreamLifecycle
objectstatic 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
objectv2TemplateOverlaps
(ClusterState currentState, String name, ComposableIndexTemplate template, boolean validate) Calculates the conflicting v2 index template overlaps for a given composable index template.static void
validateV2TemplateRequest
(Metadata metadata, String name, ComposableIndexTemplate template)
-
Field Details
-
DEFAULT_TIMESTAMP_FIELD
- See Also:
-
DEFAULT_TIMESTAMP_MAPPING_WITHOUT_ROUTING
-
-
Constructor Details
-
MetadataIndexTemplateService
@Inject public MetadataIndexTemplateService(ClusterService clusterService, MetadataCreateIndexService metadataCreateIndexService, IndicesService indicesService, IndexScopedSettings indexScopedSettings, NamedXContentRegistry xContentRegistry, SystemIndices systemIndices, IndexSettingProviders indexSettingProviders)
-
-
Method Details
-
removeTemplates
public void removeTemplates(MetadataIndexTemplateService.RemoveRequest request, ActionListener<AcknowledgedResponse> listener) -
putComponentTemplate
public void putComponentTemplate(String cause, boolean create, String name, 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 -
addComponentTemplate
public ClusterState addComponentTemplate(ClusterState currentState, boolean create, String name, ComponentTemplate template) throws Exception - Throws:
Exception
-
removeComponentTemplate
public void removeComponentTemplate(String[] names, 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. -
innerRemoveComponentTemplate
-
putIndexTemplateV2
public void putIndexTemplateV2(String cause, boolean create, String name, 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
-
addIndexTemplateV2
public ClusterState addIndexTemplateV2(ClusterState currentState, boolean create, String name, ComposableIndexTemplate template, boolean validateV2Overlaps) throws Exception - Throws:
Exception
-
v2TemplateOverlaps
public static Map<String,List<String>> v2TemplateOverlaps(ClusterState currentState, String name, ComposableIndexTemplate template, boolean validate) Calculates the conflicting v2 index template overlaps for a given composable index template. Optionally if validate is true we throw anIllegalArgumentException
with information about the conflicting templates.This method doesn't check for conflicting overlaps with v1 templates.
- Parameters:
currentState
- the current cluster statename
- the composable index template nametemplate
- the full composable index template object we check for overlapsvalidate
- should we throwIllegalArgumentException
if conflicts are found or just compute them- Returns:
- a map of v2 template names to their index patterns for v2 templates that would overlap with the given template
-
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, 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. -
innerRemoveIndexTemplateV2
-
putTemplate
public void putTemplate(MetadataIndexTemplateService.PutRequest request, ActionListener<AcknowledgedResponse> 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) Collect the given v2 template into an ordered list of mappings. -
collectMappings
public static List<CompressedXContent> collectMappings(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates, String indexName) Collect the given v2 template into an ordered list of mappings. -
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
Resolve the given v1 templates into an ordered list of aliases -
resolveAliases
public static List<Map<String,AliasMetadata>> resolveAliases(Metadata metadata, String templateName) Resolve the given v2 template name into an ordered list of aliases -
resolveLifecycle
@Nullable public static DataStreamLifecycle resolveLifecycle(Metadata metadata, String templateName) Resolve the given v2 template into aDataStreamLifecycle
object -
resolveLifecycle
@Nullable public static DataStreamLifecycle resolveLifecycle(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates) Resolve the provided v2 template and component templates into aDataStreamLifecycle
object -
composeDataLifecycles
@Nullable public static DataStreamLifecycle composeDataLifecycles(List<DataStreamLifecycle> lifecycles) This method composes a series of lifecycles to a final one. The lifecycles are getting composed one level deep, meaning that the keys present on the latest lifecycle will override the ones of the others. If a key is missing then it keeps the value of the previous lifecycles. For example, if we have the following two lifecycles: [ { "lifecycle": { "enabled": true, "data_retention" : "10d" } }, { "lifecycle": { "enabled": true, "data_retention" : "20d" } } ] The result will be { "lifecycle": { "enabled": true, "data_retention" : "20d"}} because the second data retention overrides the first. However, if we have the following two lifecycles: [ { "lifecycle": { "enabled": false, "data_retention" : "10d" } }, { "lifecycle": { "enabled": true } } ] The result will be { "lifecycle": { "enabled": true, "data_retention" : "10d"} } because the latest lifecycle does not have any information on retention.- Parameters:
lifecycles
- a sorted list of lifecycles in the order that they will be composed- Returns:
- the final lifecycle
-