-
Notifications
You must be signed in to change notification settings - Fork 159
Fix up the 'Templates' section #2178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
1cbbbf6
64e5de5
40c8af3
82c79e9
e18d68b
d267edf
c8d8411
c98afa1
9b28bdd
361af7f
ad31d5f
814535e
a1a523e
24fb6bf
d20acbd
2b6d961
982fe22
f7a213d
f9e621d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,27 +8,80 @@ products: | |
- id: elasticsearch | ||
--- | ||
|
||
# Templates [index-templates] | ||
# Templates [elasticsearch-templates] | ||
|
||
::::{note} | ||
This topic describes the composable index templates introduced in {{es}} 7.8. For information about how index templates worked previously, see the [legacy template documentation](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-template). | ||
:::: | ||
Templates are tools used to construct indices in {{es}}. They specify the properties that each created index will have. | ||
kilfoyle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
You configure templates prior to creating indices. This way, when each index is created, either manually or through the indexing of a document, the template settings are used as a basis for creating the index. When used with a [data stream](/manage-data/data-store/data-streams.md), a template configures the stream's backing indices as they are created. | ||
kilfoyle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
$$$getting$$$ | ||
An index template is a way to tell {{es}} how to configure an index when it is created. For data streams, the index template configures the stream’s backing indices as they are created. Templates are configured **prior to index creation**. When an index is created - either manually or through indexing a document - the template settings are used as a basis for creating the index. | ||
There are two types of template: | ||
|
||
There are two types of templates: index templates and [component templates](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-component-template). Component templates are reusable building blocks that configure mappings, settings, and aliases. While you can use component templates to construct index templates, they aren’t directly applied to a set of indices. Index templates can contain a collection of component templates, as well as directly specify settings, mappings, and aliases. | ||
* An [**index template**](#index-templates) is used to configure indices when they are created, by specifying the mappings, settings, and aliases that each index inherits. | ||
kilfoyle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
The following conditions apply to index templates: | ||
* A [**component template**](#component-templates) is a reusable building block used to construct index templates. | ||
kilfoyle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
* Composable templates take precedence over legacy templates. If no composable template matches a given index, a legacy template may still match and be applied. | ||
The following conditions apply to using templates: | ||
kilfoyle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
* Composable index templates take precedence over legacy templates. If no composable template matches a given index, a legacy template may still match and be applied. | ||
|
||
* If an index is created with explicit settings and also matches an index template, the settings from the [create index](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-create) request take precedence over settings specified in the index template and its component templates. | ||
* Settings specified in the index template itself take precedence over the settings in its component templates. | ||
* If a new data stream or index matches more than one index template, the index template with the highest priority is used. | ||
* When you create an index template, be careful to avoid [naming pattern collisions](#avoid-index-pattern-collisions) with built-in {{es}} index templates. | ||
|
||
|
||
## Index templates [index-templates] | ||
|
||
An **index template** is used to configure an index when it is created. [Mappings](/manage-data/data-store/mapping.md), [settings](elasticsearch://reference/elasticsearch/index-settings/index.md), and [aliases](/manage-data/data-store/aliases.md) specified in the index template are inherited by each created index. These can be specified directly in the index template, and they can be specified in one or more component templates used to construct the index template. | ||
kilfoyle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
You can create and manage index templates on the **Index management** page in {{kib}} or by using the [index template](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-index-template) API. | ||
|
||
For the {{kib}} steps and a walk-through example, refer to [Manage index templates](/manage-data/data-store/index-basics.md#index-management-manage-index-templates). | ||
|
||
Using the API, the following request creates an index template that is *composed of* the two component templates shown in the [component templates](#component-templates) example. | ||
|
||
```console | ||
PUT _index_template/template_1 | ||
{ | ||
"index_patterns": ["te*", "bar*"], | ||
"template": { | ||
"settings": { | ||
"number_of_shards": 1 | ||
}, | ||
"mappings": { | ||
"_source": { | ||
"enabled": true | ||
}, | ||
"properties": { | ||
"host_name": { | ||
"type": "keyword" | ||
}, | ||
"created_at": { | ||
"type": "date", | ||
"format": "EEE MMM dd HH:mm:ss Z yyyy" | ||
} | ||
} | ||
}, | ||
"aliases": { | ||
"mydata": { } | ||
} | ||
}, | ||
"priority": 501, | ||
"composed_of": ["component_template1", "runtime_component_template"], | ||
"version": 3, | ||
"_meta": { | ||
"description": "my custom" | ||
} | ||
} | ||
``` | ||
|
||
::::{admonition} Avoid index pattern collisions | ||
:name: avoid-index-pattern-collisions | ||
:::{tip} | ||
The following features can be useful when you're setting up index templates: | ||
|
||
* You can test the effect of an index template before putting it into use. Refer to [Simulate multi-component templates](/manage-data/data-store/templates/simulate-multi-component-templates.md) to learn more. | ||
* You can create an index template for a component template that does not yet exist. When doing so, you can use the `ignore_missing_component_templates` configuration option in an index template so that the missing component template is ignored. Refer to [Ignore missing component templates](/manage-data/data-store/templates/ignore-missing-component-templates.md) to learn more. | ||
::: | ||
|
||
### Avoid index pattern collisions [avoid-index-pattern-collisions] | ||
|
||
{{es}} has built-in index templates, each with a priority of `100`, for the following index patterns: | ||
|
||
|
@@ -49,15 +102,13 @@ If you use {{fleet}} or {{agent}}, assign your index templates a priority lower | |
* To avoid naming collisions with built-in and Fleet-managed index templates, avoid using `@` as part of the name of your own index templates. | ||
* Beginning in {{stack}} version 9.1, {{fleet}} uses indices named `fleet-synced-integrations*` for a feature. Avoid using this name to avoid collisions with built-in indices. | ||
|
||
:::: | ||
|
||
## Component templates [component-templates] | ||
|
||
A **component template** is a reusable building block, containing mappings, settings, and aliases, used to construct an index template. Component templates are used only to construct index templates and are not applied to indices directly. | ||
kilfoyle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Create index template [create-index-templates] | ||
You can create and manage component templates on the **Index management** page in {{kib}} or by using the [component template](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-component-template) API. For the {{kib}} steps, refer to [Manage component templates](/manage-data/data-store/index-basics.md#index-management-manage-component-templates). | ||
|
||
Use the [put index template](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-index-template) and [put component template](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-component-template) APIs to create and update index templates. You can also [manage index templates](/manage-data/data-store/index-basics.md#index-management) from Stack Management in {{kib}}. | ||
|
||
The following requests create two component templates. | ||
Using the API, the following request creates the two component templates used in the previous index template example: | ||
|
||
```console | ||
PUT _component_template/component_template1 | ||
|
@@ -91,41 +142,3 @@ PUT _component_template/runtime_component_template | |
``` | ||
|
||
1. This component template adds a [runtime field](mapping/map-runtime-field.md) named `day_of_week` to the mappings when a new index matches the template. | ||
|
||
|
||
The following request creates an index template that is *composed of* these component templates. | ||
|
||
```console | ||
PUT _index_template/template_1 | ||
{ | ||
"index_patterns": ["te*", "bar*"], | ||
"template": { | ||
"settings": { | ||
"number_of_shards": 1 | ||
}, | ||
"mappings": { | ||
"_source": { | ||
"enabled": true | ||
}, | ||
"properties": { | ||
"host_name": { | ||
"type": "keyword" | ||
}, | ||
"created_at": { | ||
"type": "date", | ||
"format": "EEE MMM dd HH:mm:ss Z yyyy" | ||
} | ||
} | ||
}, | ||
"aliases": { | ||
"mydata": { } | ||
} | ||
}, | ||
"priority": 501, | ||
"composed_of": ["component_template1", "runtime_component_template"], | ||
"version": 3, | ||
"_meta": { | ||
"description": "my custom" | ||
} | ||
} | ||
``` |
Uh oh!
There was an error while loading. Please reload this page.