2020-07-24 10:02:11 +08:00
|
|
|
[[index-templates]]
|
|
|
|
= Index templates
|
2020-04-29 05:58:40 +08:00
|
|
|
|
2020-07-24 10:02:11 +08:00
|
|
|
NOTE: This topic describes the composable index templates introduced in {es} 7.8.
|
|
|
|
For information about how index templates worked previously,
|
|
|
|
see the <<indices-templates-v1,legacy template documentation>>.
|
2020-04-29 05:58:40 +08:00
|
|
|
|
2020-06-04 08:14:20 +08:00
|
|
|
[[getting]]
|
2020-07-14 23:49:24 +08:00
|
|
|
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 and then when an
|
|
|
|
index is created either manually or through indexing a document, the template
|
|
|
|
settings are used as a basis for creating the index.
|
2020-04-29 05:58:40 +08:00
|
|
|
|
|
|
|
There are two types of templates, index templates and <<indices-component-template,component
|
|
|
|
templates>>. Component templates are reusable building blocks that configure mappings, settings, and
|
|
|
|
aliases. You 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.
|
|
|
|
|
2020-07-14 23:49:24 +08:00
|
|
|
If a new data stream or index matches more than one index template, the index template with the highest priority is used.
|
2020-04-29 05:58:40 +08:00
|
|
|
|
2021-02-02 01:34:21 +08:00
|
|
|
// tag::built-in-index-templates[]
|
2020-08-17 23:37:08 +08:00
|
|
|
[IMPORTANT]
|
|
|
|
====
|
2021-02-02 21:35:21 +08:00
|
|
|
{es} has built-in index templates, each with a priority of `100`, for the
|
|
|
|
following index patterns:
|
2020-08-17 23:37:08 +08:00
|
|
|
|
2021-02-02 21:35:21 +08:00
|
|
|
// tag::built-in-index-template-patterns[]
|
|
|
|
- `logs-*-*`
|
|
|
|
- `metrics-*-*`
|
|
|
|
- `synthetics-*-*`
|
|
|
|
// end::built-in-index-template-patterns[]
|
2020-08-26 20:10:49 +08:00
|
|
|
|
2021-02-02 21:35:21 +08:00
|
|
|
The {fleet-guide}/fleet-overview.html[{agent}] uses these templates to create
|
2021-02-16 23:53:28 +08:00
|
|
|
data streams. Index templates created by {fleet} integrations use similar
|
|
|
|
overlapping index patterns and have a priority up to `200`.
|
|
|
|
|
|
|
|
If you use {fleet} or the {agent}, assign your index templates a priority
|
|
|
|
lower than `100` to avoid overriding these templates. Otherwise, to avoid
|
|
|
|
accidentally applying the templates, do one or more of the following:
|
2021-02-02 21:35:21 +08:00
|
|
|
|
|
|
|
- To disable all built-index index and component templates, set
|
|
|
|
<<stack-templates-enabled,`stack.templates.enabled`>> to `false` using the
|
|
|
|
<<cluster-update-settings,cluster update settings API>>.
|
|
|
|
|
|
|
|
- Use a non-overlapping index pattern.
|
|
|
|
|
2021-02-16 23:53:28 +08:00
|
|
|
- Assign templates with an overlapping pattern a `priority` higher than `200`.
|
|
|
|
For example, if you don't use {fleet} or the {agent} and want to create a
|
|
|
|
template for the `logs-*` index pattern, assign your template a priority of
|
|
|
|
`500`. This ensures your template is applied instead of the built-in template
|
|
|
|
for `logs-*-*`.
|
2020-08-17 23:37:08 +08:00
|
|
|
====
|
2021-02-02 01:34:21 +08:00
|
|
|
// end::built-in-index-templates[]
|
2020-08-17 23:37:08 +08:00
|
|
|
|
2020-07-24 10:02:11 +08:00
|
|
|
When a composable template matches a given index
|
|
|
|
it always takes precedence over a legacy template. If no composable template matches, a legacy
|
|
|
|
template may still match and be applied.
|
|
|
|
|
2020-05-28 19:11:15 +08:00
|
|
|
If an index is created with explicit settings and also matches an index template,
|
2020-04-29 05:58:40 +08:00
|
|
|
the settings from the create index request take precedence over settings specified in the index template and its component templates.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
2020-05-15 05:33:35 +08:00
|
|
|
PUT _component_template/component_template1
|
|
|
|
{
|
|
|
|
"template": {
|
|
|
|
"mappings": {
|
|
|
|
"properties": {
|
|
|
|
"@timestamp": {
|
|
|
|
"type": "date"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PUT _component_template/other_component_template
|
|
|
|
{
|
|
|
|
"template": {
|
|
|
|
"mappings": {
|
|
|
|
"properties": {
|
|
|
|
"ip_address": {
|
|
|
|
"type": "ip"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 05:58:40 +08:00
|
|
|
PUT _index_template/template_1
|
|
|
|
{
|
|
|
|
"index_patterns": ["te*", "bar*"],
|
|
|
|
"template": {
|
|
|
|
"settings": {
|
|
|
|
"number_of_shards": 1
|
|
|
|
},
|
|
|
|
"mappings": {
|
|
|
|
"_source": {
|
|
|
|
"enabled": false
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"host_name": {
|
|
|
|
"type": "keyword"
|
|
|
|
},
|
|
|
|
"created_at": {
|
|
|
|
"type": "date",
|
|
|
|
"format": "EEE MMM dd HH:mm:ss Z yyyy"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"aliases": {
|
|
|
|
"mydata": { }
|
|
|
|
}
|
|
|
|
},
|
2021-02-16 23:53:28 +08:00
|
|
|
"priority": 500,
|
2020-04-29 05:58:40 +08:00
|
|
|
"composed_of": ["component_template1", "other_component_template"],
|
|
|
|
"version": 3,
|
|
|
|
"_meta": {
|
|
|
|
"description": "my custom"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TESTSETUP
|
|
|
|
|
2020-07-24 10:02:11 +08:00
|
|
|
////
|
2020-04-29 05:58:40 +08:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
2020-05-19 05:11:42 +08:00
|
|
|
DELETE _index_template/*
|
2020-04-29 05:58:40 +08:00
|
|
|
DELETE _component_template/*
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEARDOWN
|
|
|
|
|
2020-07-24 10:02:11 +08:00
|
|
|
////
|
2020-05-28 19:11:15 +08:00
|
|
|
|
2020-07-24 10:02:11 +08:00
|
|
|
include::simulate-multi-component-templates.asciidoc[]
|