diff --git a/docs/reference/indices.asciidoc b/docs/reference/indices.asciidoc index b595904a212..e980b0971c7 100644 --- a/docs/reference/indices.asciidoc +++ b/docs/reference/indices.asciidoc @@ -58,8 +58,11 @@ index settings, data streams, aliases, mappings, and index templates. [[index-templates]] === Index templates: * <> -* <> +* <> * <> +* <> +* <> +* <> * <> [float] diff --git a/docs/reference/indices/component-templates.asciidoc b/docs/reference/indices/component-templates.asciidoc index b12a4daf98c..936d34147ea 100644 --- a/docs/reference/indices/component-templates.asciidoc +++ b/docs/reference/indices/component-templates.asciidoc @@ -1,7 +1,7 @@ [[indices-component-template]] -=== Component template API +=== Put component template API ++++ -Component template +Put component template ++++ Component templates are building blocks that specify mappings, settings, or alias configuration, but @@ -74,66 +74,6 @@ You can use C-style /* */ block comments in component templates. You can include comments anywhere in the request body, except before the opening curly bracket. -[[getting-component-templates]] -===== Getting component templates - -=== Get component template API -++++ -Get component template -++++ - -Returns information about one or more component templates. - -[source,console] --------------------------------------------------- -GET /_component_template/template_1 --------------------------------------------------- - -[[get-component-template-api-request]] -==== {api-request-title} - -`GET /_component-template/` - - -[[get-component-template-api-path-params]] -==== {api-path-parms-title} - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-template] -+ -To return all component templates, omit this parameter or use a value of `*`. - - -[[get-component-template-api-query-params]] -==== {api-query-parms-title} - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=flat-settings] - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=local] - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=master-timeout] - - -[[get-component-template-api-example]] -==== {api-examples-title} - - -[[get-component-template-api-wildcard-ex]] -===== Get component templates using a wildcard expression - -[source,console] --------------------------------------------------- -GET /_component_template/temp* --------------------------------------------------- - - -[[get-component-template-api-all-ex]] -===== Get all component templates - -[source,console] --------------------------------------------------- -GET /_component_template --------------------------------------------------- - [[put-component-template-api-path-params]] ==== {api-path-parms-title} @@ -270,3 +210,61 @@ PUT /_component_template/template_1 -------------------------------------------------- To check the `_meta`, you can use the <> API. + +[[getting-component-templates]] +=== Get component template API +++++ +Get component template +++++ + +Returns information about one or more component templates. + +[source,console] +-------------------------------------------------- +GET /_component_template/template_1 +-------------------------------------------------- + +[[get-component-template-api-request]] +==== {api-request-title} + +`GET /_component-template/` + + +[[get-component-template-api-path-params]] +==== {api-path-parms-title} + +include::{docdir}/rest-api/common-parms.asciidoc[tag=index-template] ++ +To return all component templates, omit this parameter or use a value of `*`. + + +[[get-component-template-api-query-params]] +==== {api-query-parms-title} + +include::{docdir}/rest-api/common-parms.asciidoc[tag=flat-settings] + +include::{docdir}/rest-api/common-parms.asciidoc[tag=local] + +include::{docdir}/rest-api/common-parms.asciidoc[tag=master-timeout] + + +[[get-component-template-api-example]] +==== {api-examples-title} + + +[[get-component-template-api-wildcard-ex]] +===== Get component templates using a wildcard expression + +[source,console] +-------------------------------------------------- +GET /_component_template/temp* +-------------------------------------------------- + + +[[get-component-template-api-all-ex]] +===== Get all component templates + +[source,console] +-------------------------------------------------- +GET /_component_template +-------------------------------------------------- diff --git a/docs/reference/indices/index-templates.asciidoc b/docs/reference/indices/index-templates.asciidoc index 19e1a9a8578..cda9a80d5d6 100644 --- a/docs/reference/indices/index-templates.asciidoc +++ b/docs/reference/indices/index-templates.asciidoc @@ -1,5 +1,5 @@ [[indices-templates]] -=== Index template API +=== Index templates ++++ Index template ++++ @@ -14,6 +14,7 @@ it always takes precedence over a legacy template. If no composable template mat template may still match and be applied. ==== +[[getting]] An index template is a way to tell {es} how to configure an index when it is 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. @@ -103,197 +104,8 @@ DELETE _component_template/* ////////////////////////// -[[put-index-template-api-request]] -==== {api-request-title} - -`PUT /_index_template/` - - -[[put-index-template-api-desc]] -==== {api-description-title} - -Creates or updates an index template. - -// tag::index-template-def[] -Index templates define <> and <> 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. -// end::index-template-def[] - -Index templates are only applied during index creation. Changes to index templates do not affect -existing indices. Settings and mappings specified in <> 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. You can include comments anywhere in -the request body, except before the opening curly bracket. - -[[getting]] -===== Getting templates - -[[indices-get-template]] -=== Get index template API -++++ -Get index template -++++ - -Returns information about one or more index templates. - -[source,console] --------------------------------------------------- -GET /_index_template/template_1 --------------------------------------------------- - - -[[get-template-api-request]] -==== {api-request-title} - -`GET /_index_template/` - - -[[get-template-api-path-params]] -==== {api-path-parms-title} - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-template] -+ -To return all index templates, omit this parameter or use a value of `*`. - - -[[get-template-api-query-params]] -==== {api-query-parms-title} - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=flat-settings] - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=local] - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=master-timeout] - - -[[get-template-api-example]] -==== {api-examples-title} - - -[[get-template-api-wildcard-ex]] -===== Get index templates using a wildcard expression - -[source,console] --------------------------------------------------- -GET /_index_template/temp* --------------------------------------------------- - - -[[get-template-api-all-ex]] -===== Get all index templates - -[source,console] --------------------------------------------------- -GET /_index_template --------------------------------------------------- - -[[put-index-template-api-path-params]] -==== {api-path-parms-title} - -``:: -(Required, string) -Name of the index template to create. - - -[[put-index-template-api-query-params]] -==== {api-query-parms-title} - -`create`:: -(Optional, boolean) -If `true`, this request cannot replace or update existing index templates. Defaults to `false`. - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=master-timeout] - - -[[put-index-template-api-request-body]] -==== {api-request-body-title} - -`index_patterns`:: -(Required, array of strings) -Array of wildcard expressions -used to match the names of indices during creation. - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=aliases] - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=mappings] - -include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=settings] - -`template`:: -(Optional, object) -This is the template to be applied, may optionally include a `mappings`, -`settings`, or `aliases` configuration. - -`composed_of`:: -(Optional, array of strings) -An ordered list of component template names. Component templates will be merged in the order -specified, meaning that the last component template specified has the highest precedence. See the -<> reference for information. - -`priority`:: -(Optional, integer) -Priority to determine index template precedence when a new index is created. The index template with -the highest priority is chosen. If no priority is specified the template is treated as though it is -of priority 0 (lowest priority). -This number is not automatically generated by {es}. - -`version`:: -(Optional, integer) -Version number used to manage index templates externally. -This number is not automatically generated by {es}. - -`_meta`:: -(Optional, object) -Optional user metadata about the index template. May have any contents. -This map is not automatically generated by {es}. - -[[put-index-template-api-example]] -==== {api-examples-title} - -==== Composing multiple component templates - -When multiple component templates are specified in the `composed_of` field for an index template, -they are merged in the order specified, meaning that later component templates override earlier -component templates. - -For two component templates, the order they are specified changes the number of shards for an index: - -[source,console] --------------------------------------------------- -PUT /_component_template/template_with_2_shards -{ - "template": { - "settings": { - "index.number_of_shards": 2 - } - } -} - -PUT /_component_template/template_with_3_shards -{ - "template": { - "settings": { - "index.number_of_shards": 3 - } - } -} - -PUT /_index_template/template_1 -{ - "index_patterns": ["t*"], - "composed_of": ["template_with_2_shards", "template_with_3_shards"] -} --------------------------------------------------- - -In this case, an index matching `t*` will have three primary shards. If the order of composed -templates were reversed, the index would have two primary shards. - - [[simulating-templates]] -===== Simulating template composition +==== Simulating template composition Since templates can be composed not only of multiple component templates, but also the index template itself, there are two simulation APIs to determine what the resulting index settings will @@ -420,6 +232,114 @@ The output of the simulate API from the last example call looks like: When simulating a template and specifying a template in the body of the request, the simulated template is not added to the existing templates, it is only used for the simulation. +[[indices-put-template]] +=== Put index template API +++++ +Put index template +++++ + +Creates or updates an index template. + +[source,console] +-------------------------------------------------- +PUT /_index_template/template_1 +{ + "index_patterns" : ["te*"], + "priority" : 1, + "template": { + "settings" : { + "number_of_shards" : 2 + } + } +} +-------------------------------------------------- + +[[put-index-template-api-request]] +==== {api-request-title} + +`PUT /_index_template/` + + +[[put-index-template-api-desc]] +==== {api-description-title} + +// tag::index-template-def[] +Index templates define <> and <> 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. +// end::index-template-def[] + +Index templates are only applied during index creation. Changes to index templates do not affect +existing indices. Settings and mappings specified in <> 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. You can include comments anywhere in +the request body, except before the opening curly bracket. + +[[put-index-template-api-path-params]] +==== {api-path-parms-title} + +``:: +(Required, string) +Name of the index template to create. + + +[[put-index-template-api-query-params]] +==== {api-query-parms-title} + +`create`:: +(Optional, boolean) +If `true`, this request cannot replace or update existing index templates. Defaults to `false`. + +include::{docdir}/rest-api/common-parms.asciidoc[tag=master-timeout] + + +[[put-index-template-api-request-body]] +==== {api-request-body-title} + +`index_patterns`:: +(Required, array of strings) +Array of wildcard expressions +used to match the names of indices during creation. + +include::{docdir}/rest-api/common-parms.asciidoc[tag=aliases] + +include::{docdir}/rest-api/common-parms.asciidoc[tag=mappings] + +include::{docdir}/rest-api/common-parms.asciidoc[tag=settings] + +`template`:: +(Optional, object) +This is the template to be applied, may optionally include a `mappings`, +`settings`, or `aliases` configuration. + +`composed_of`:: +(Optional, array of strings) +An ordered list of component template names. Component templates are merged in the order +specified, meaning that the last component template specified has the highest precedence. See +<> for an example. + +`priority`:: +(Optional, integer) +Priority to determine index template precedence when a new index is created. The index template with +the highest priority is chosen. If no priority is specified the template is treated as though it is +of priority 0 (lowest priority). +This number is not automatically generated by {es}. + +`version`:: +(Optional, integer) +Version number used to manage index templates externally. +This number is not automatically generated by {es}. + +`_meta`:: +(Optional, object) +Optional user metadata about the index template. May have any contents. +This map is not automatically generated by {es}. + +[[put-index-template-api-example]] +==== {api-examples-title} + ===== Index template with index aliases You can include <> in an index template. @@ -588,3 +508,100 @@ Required properties of a data stream definition: (Required, string) The name of the timestamp field. This field must be present in all documents indexed into the data stream and must be of type <> or <>. + +[[multiple-component-templates]] +===== Composing multiple component templates + +When multiple component templates are specified in the `composed_of` field for an index template, +they are merged in the order specified, meaning that later component templates override earlier +component templates. + +For two component templates, the order they are specified changes the number of shards for an index: + +[source,console] +-------------------------------------------------- +PUT /_component_template/template_with_2_shards +{ + "template": { + "settings": { + "index.number_of_shards": 2 + } + } +} + +PUT /_component_template/template_with_3_shards +{ + "template": { + "settings": { + "index.number_of_shards": 3 + } + } +} + +PUT /_index_template/template_1 +{ + "index_patterns": ["t*"], + "composed_of": ["template_with_2_shards", "template_with_3_shards"] +} +-------------------------------------------------- + +In this case, an index matching `t*` will have three primary shards. If the order of composed +templates were reversed, the index would have two primary shards. + +[[indices-get-template]] +=== Get index template API [[getting-templates]] +++++ +Get index template +++++ + +Returns information about one or more index templates. + +[source,console] +-------------------------------------------------- +GET /_index_template/template_1 +-------------------------------------------------- + +[[get-template-api-request]] +==== {api-request-title} + +`GET /_index_template/` + + +[[get-template-api-path-params]] +==== {api-path-parms-title} + +include::{docdir}/rest-api/common-parms.asciidoc[tag=index-template] ++ +To return all index templates, omit this parameter or use a value of `*`. + + +[[get-template-api-query-params]] +==== {api-query-parms-title} + +include::{docdir}/rest-api/common-parms.asciidoc[tag=flat-settings] + +include::{docdir}/rest-api/common-parms.asciidoc[tag=local] + +include::{docdir}/rest-api/common-parms.asciidoc[tag=master-timeout] + + +[[get-template-api-example]] +==== {api-examples-title} + + +[[get-template-api-wildcard-ex]] +===== Get index templates using a wildcard expression + +[source,console] +-------------------------------------------------- +GET /_index_template/temp* +-------------------------------------------------- + + +[[get-template-api-all-ex]] +===== Get all index templates + +[source,console] +-------------------------------------------------- +GET /_index_template +--------------------------------------------------