2020-04-28 18:10:50 -04:00
|
|
|
[[indices-templates-v1]]
|
2019-09-04 11:47:32 -04:00
|
|
|
=== Put index template API
|
|
|
|
++++
|
2020-07-23 22:48:19 -04:00
|
|
|
<titleabbrev>Put index template (legacy)</titleabbrev>
|
2019-09-04 11:47:32 -04:00
|
|
|
++++
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-07-23 22:48:19 -04:00
|
|
|
IMPORTANT: This documentation is about legacy index templates,
|
|
|
|
which are deprecated and will be replaced by the composable templates introduced in {es} 7.8.
|
|
|
|
For information about composable templates, <<indices-templates>>.
|
2020-04-28 18:10:50 -04:00
|
|
|
|
2019-09-04 11:47:32 -04:00
|
|
|
Creates or updates an index template.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-04-29 10:42:03 -04:00
|
|
|
PUT _template/template_1
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2016-11-10 18:00:30 -05:00
|
|
|
"index_patterns": ["te*", "bar*"],
|
2016-04-04 13:29:07 -04:00
|
|
|
"settings": {
|
|
|
|
"number_of_shards": 1
|
|
|
|
},
|
|
|
|
"mappings": {
|
2019-01-14 16:08:01 -05:00
|
|
|
"_source": {
|
|
|
|
"enabled": false
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"host_name": {
|
|
|
|
"type": "keyword"
|
2016-04-04 13:29:07 -04:00
|
|
|
},
|
2019-01-14 16:08:01 -05:00
|
|
|
"created_at": {
|
|
|
|
"type": "date",
|
|
|
|
"format": "EEE MMM dd HH:mm:ss Z yyyy"
|
2016-04-04 13:29:07 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2016-04-04 13:29:07 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-09-02 18:22:30 -04:00
|
|
|
// TESTSETUP
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-01-28 03:52:24 -05:00
|
|
|
//////////////////////////
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
2020-01-28 09:36:29 -05:00
|
|
|
DELETE _template/template_*
|
2020-01-28 03:52:24 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
// TEARDOWN
|
|
|
|
|
|
|
|
//////////////////////////
|
2016-10-08 06:38:45 -04:00
|
|
|
|
2020-04-28 18:10:50 -04:00
|
|
|
[[put-index-template-v1-api-request]]
|
2019-09-04 11:47:32 -04:00
|
|
|
==== {api-request-title}
|
|
|
|
|
|
|
|
`PUT /_template/<index-template>`
|
|
|
|
|
|
|
|
|
2020-04-28 18:10:50 -04:00
|
|
|
[[put-index-template-v1-api-desc]]
|
2019-09-04 11:47:32 -04:00
|
|
|
==== {api-description-title}
|
|
|
|
|
|
|
|
Use the PUT index template API
|
|
|
|
to create or update an index template.
|
|
|
|
|
|
|
|
Index templates define <<index-modules-settings,settings>> and <<mapping,mappings>>
|
|
|
|
that you can automatically apply when creating new indices.
|
|
|
|
{es} applies templates to new indices
|
|
|
|
based on an index pattern that matches the index name.
|
2020-07-23 22:48:19 -04:00
|
|
|
|
|
|
|
NOTE: Composable templates always take precedence over legacy templates.
|
|
|
|
If no composable template matches a new index,
|
|
|
|
matching legacy templates are applied according to their order.
|
2019-09-04 11:47:32 -04:00
|
|
|
|
|
|
|
Index templates are only applied during index creation.
|
|
|
|
Changes to index templates do not affect existing indices.
|
|
|
|
Settings and mappings specified in <<indices-create-index, create index>> API requests
|
|
|
|
override any settings or mappings specified in an index template.
|
|
|
|
|
|
|
|
===== Comments in index templates
|
|
|
|
You can use C-style /* */ block comments in index templates.
|
2019-11-29 12:42:02 -05:00
|
|
|
You can include comments anywhere in the request body,
|
2019-09-04 11:47:32 -04:00
|
|
|
except before the opening curly bracket.
|
|
|
|
|
2020-04-28 18:10:50 -04:00
|
|
|
[[getting-v1]]
|
2019-09-04 11:47:32 -04:00
|
|
|
===== Getting templates
|
|
|
|
|
2020-04-28 18:10:50 -04:00
|
|
|
See <<indices-get-template-v1>>.
|
2019-09-04 11:47:32 -04:00
|
|
|
|
|
|
|
|
2020-04-28 18:10:50 -04:00
|
|
|
[[put-index-template-v1-api-path-params]]
|
2019-09-04 11:47:32 -04:00
|
|
|
==== {api-path-parms-title}
|
|
|
|
|
|
|
|
`<index-template>`::
|
|
|
|
(Required, string)
|
|
|
|
Name of the index template to create.
|
|
|
|
|
|
|
|
|
2020-04-28 18:10:50 -04:00
|
|
|
[[put-index-template-v1-api-query-params]]
|
2019-09-04 11:47:32 -04:00
|
|
|
==== {api-query-parms-title}
|
|
|
|
|
|
|
|
`create`::
|
|
|
|
(Optional, boolean)
|
|
|
|
If `true`, this request cannot replace or update existing index templates.
|
|
|
|
Defaults to `false`.
|
|
|
|
|
|
|
|
`order`::
|
|
|
|
(Optional,integer)
|
|
|
|
Order in which {es} applies this template
|
|
|
|
if index matches multiple templates.
|
|
|
|
+
|
|
|
|
Templates with lower `order` values are merged first.
|
|
|
|
Templates with higher `order` values are merged later,
|
|
|
|
overriding templates with lower values.
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
|
2019-09-04 11:47:32 -04:00
|
|
|
|
|
|
|
|
2020-04-28 18:10:50 -04:00
|
|
|
[[put-index-template-v1-api-request-body]]
|
2019-09-04 11:47:32 -04:00
|
|
|
==== {api-request-body-title}
|
|
|
|
|
|
|
|
`index_patterns`::
|
|
|
|
(Required, array of strings)
|
|
|
|
Array of wildcard expressions
|
|
|
|
used to match the names of indices during creation.
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=aliases]
|
2019-09-04 11:47:32 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=mappings]
|
2019-09-04 11:47:32 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=settings]
|
2019-09-04 11:47:32 -04:00
|
|
|
|
2019-09-05 10:18:15 -04:00
|
|
|
`version`::
|
|
|
|
(Optional, integer)
|
|
|
|
Version number used to manage index templates externally.
|
|
|
|
This number is not automatically generated by {es}.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-04 11:47:32 -04:00
|
|
|
|
2020-04-28 18:10:50 -04:00
|
|
|
[[put-index-template-v1-api-example]]
|
2019-09-04 11:47:32 -04:00
|
|
|
==== {api-examples-title}
|
|
|
|
|
|
|
|
===== Index template with index aliases
|
|
|
|
|
|
|
|
You can include <<indices-aliases,index aliases>> in an index template.
|
2013-11-26 06:32:25 -05:00
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2013-11-26 06:32:25 -05:00
|
|
|
--------------------------------------------------
|
2016-09-02 18:22:30 -04:00
|
|
|
PUT _template/template_1
|
2013-11-26 06:32:25 -05:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"index_patterns" : ["te*"],
|
|
|
|
"settings" : {
|
|
|
|
"number_of_shards" : 1
|
|
|
|
},
|
|
|
|
"aliases" : {
|
|
|
|
"alias1" : {},
|
|
|
|
"alias2" : {
|
|
|
|
"filter" : {
|
|
|
|
"term" : {"user" : "kimchy" }
|
|
|
|
},
|
|
|
|
"routing" : "kimchy"
|
2013-11-26 06:32:25 -05:00
|
|
|
},
|
2020-07-21 15:49:58 -04:00
|
|
|
"{index}-alias" : {} <1>
|
|
|
|
}
|
2013-11-26 06:32:25 -05:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2016-11-18 10:55:04 -05:00
|
|
|
<1> the `{index}` placeholder in the alias name will be replaced with the
|
|
|
|
actual index name that the template gets applied to, during index creation.
|
2013-11-26 06:32:25 -05:00
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-04-28 18:10:50 -04:00
|
|
|
[[multiple-templates-v1]]
|
2019-09-04 11:47:32 -04:00
|
|
|
===== Indices matching multiple templates
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Multiple index templates can potentially match an index, in this case,
|
|
|
|
both the settings and mappings are merged into the final configuration
|
|
|
|
of the index. The order of the merging can be controlled using the
|
|
|
|
`order` parameter, with lower order being applied first, and higher
|
|
|
|
orders overriding them. For example:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-09-02 18:22:30 -04:00
|
|
|
PUT /_template/template_1
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"index_patterns" : ["te*"],
|
|
|
|
"order" : 0,
|
|
|
|
"settings" : {
|
|
|
|
"number_of_shards" : 1
|
|
|
|
},
|
|
|
|
"mappings" : {
|
|
|
|
"_source" : { "enabled" : false }
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
|
2016-09-02 18:22:30 -04:00
|
|
|
PUT /_template/template_2
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"index_patterns" : ["tes*"],
|
|
|
|
"order" : 1,
|
|
|
|
"settings" : {
|
|
|
|
"number_of_shards" : 1
|
|
|
|
},
|
|
|
|
"mappings" : {
|
|
|
|
"_source" : { "enabled" : true }
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2018-06-04 09:42:29 -04:00
|
|
|
The above will disable storing the `_source`, but
|
2020-07-01 11:32:32 -04:00
|
|
|
for indices that start with `tes*`, `_source` will still be enabled.
|
2013-08-28 19:24:34 -04:00
|
|
|
Note, for mappings, the merging is "deep", meaning that specific
|
|
|
|
object/property based mappings can easily be added/overridden on higher
|
|
|
|
order templates, with lower order templates providing the basis.
|
2016-10-18 11:56:18 -04:00
|
|
|
|
2020-01-28 03:52:24 -05:00
|
|
|
NOTE: Multiple matching templates with the same order value will
|
2018-11-29 23:56:32 -05:00
|
|
|
result in a non-deterministic merging order.
|
2019-09-05 10:18:15 -04:00
|
|
|
|
|
|
|
|
2020-04-28 18:10:50 -04:00
|
|
|
[[versioning-templates-v1]]
|
2020-01-28 03:52:24 -05:00
|
|
|
===== Template versioning
|
2019-09-05 10:18:15 -04:00
|
|
|
|
|
|
|
You can use the `version` parameter
|
|
|
|
to add an optional version number to an index template.
|
|
|
|
External systems can use these version numbers
|
|
|
|
to simplify template management.
|
|
|
|
|
|
|
|
The `version` parameter is completely optional
|
|
|
|
and not automatically generated by {es}.
|
|
|
|
|
|
|
|
To unset a `version`,
|
2020-01-28 03:52:24 -05:00
|
|
|
replace the template without specifying one.
|
2019-09-05 10:18:15 -04:00
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2020-01-28 03:52:24 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
PUT /_template/template_1
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"index_patterns" : ["myindex-*"],
|
|
|
|
"order" : 0,
|
|
|
|
"settings" : {
|
|
|
|
"number_of_shards" : 1
|
|
|
|
},
|
|
|
|
"version": 123
|
2020-01-28 03:52:24 -05:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-05 10:18:15 -04:00
|
|
|
|
|
|
|
To check the `version`,
|
|
|
|
you can use the <<indices-get-template, get index template>> API
|
|
|
|
with the <<common-options-response-filtering, `filter_path`>> query parameter
|
2020-01-28 03:52:24 -05:00
|
|
|
to return only the version number:
|
2019-09-05 10:18:15 -04:00
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2020-01-28 03:52:24 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
GET /_template/template_1?filter_path=*.version
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
2019-09-05 10:18:15 -04:00
|
|
|
|
|
|
|
The API returns the following response:
|
|
|
|
|
2019-09-06 16:09:09 -04:00
|
|
|
[source,console-result]
|
2020-01-28 03:52:24 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"template_1" : {
|
|
|
|
"version" : 123
|
|
|
|
}
|
|
|
|
}
|
2020-07-02 22:05:32 -04:00
|
|
|
--------------------------------------------------
|