Skip to content

Commit

Permalink
[7.x] Initial documentation for index templates V2 (#55755) (#55898)
Browse files Browse the repository at this point in the history
Backports the following commits to 7.x:
 - Initial documentation for index templates V2 (#55755)
  • Loading branch information
dakrone authored Apr 28, 2020
1 parent f8db1a5 commit 4315a55
Show file tree
Hide file tree
Showing 7 changed files with 725 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ testClusters.integTest {

// TODO: remove this once cname is prepended to transport.publish_address by default in 8.0
systemProperty 'es.transport.cname_in_publish_address', 'true'
systemProperty 'es.itv2_feature_enabled', 'true'
}

// build the cluster with all plugins
Expand Down
9 changes: 9 additions & 0 deletions docs/reference/indices.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ index settings, aliases, mappings, and index templates.
* <<indices-get-template>>
* <<indices-template-exists>>

[float]
[[component-template-apis]]
=== Component templates:
* <<indices-component-template>>

[float]
[[monitoring]]
=== Monitoring:
Expand Down Expand Up @@ -125,6 +130,10 @@ include::indices/template-exists.asciidoc[]

include::indices/open-close.asciidoc[]

include::indices/index-templates.asciidoc[]

include::indices/component-templates.asciidoc[]

include::indices/templates.asciidoc[]

include::indices/put-mapping.asciidoc[]
Expand Down
272 changes: 272 additions & 0 deletions docs/reference/indices/component-templates.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
[[indices-component-template]]
=== Component template API
++++
<titleabbrev>Component template</titleabbrev>
++++

Component templates are building blocks that specify mappings, settings, or alias configuration, but
don't apply to a set of indices themselves. To be used a component template must be specified in the
`composed_of` of an <<indices-templates,index template>>.

[source,console]
--------------------------------------------------
PUT _component_template/template_1
{
"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"
}
}
}
}
}
--------------------------------------------------
// TESTSETUP

//////////////////////////
[source,console]
--------------------------------------------------
DELETE _component_template/template_*
--------------------------------------------------
// TEARDOWN
//////////////////////////

[[put-component-template-api-request]]
==== {api-request-title}

`PUT /_component_template/<component-template>`


[[put-component-template-api-desc]]
==== {api-description-title}

Use the PUT component template API to create or update a component template.

// tag::component-template-def[]
Component templates define <<index-modules-settings,settings>>, <<mapping,mappings>>, and
<<indices-aliases,aliases>> that you can automatically apply when creating new indices. On their own
component templates are not matched or applied to an index, instead they are used in the
`composed_of` definition of an <<indices-templates,index template>> to make up the final index
configuration.
// end::component-template-def[]

Component templates are only used during index creation. Changes to component templates do not
affect existing indices. Settings and mappings specified in <<indices-create-index, create index>>
API requests and <<indices-templates,index templates>> override any settings or mappings specified
in a component template.

===== Comments in component templates
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
++++
<titleabbrev>Get component template</titleabbrev>
++++

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/<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
--------------------------------------------------

[[put-component-template-api-path-params]]
==== {api-path-parms-title}

`<component-template>`::
(Required, string)
Name of the component template to create.


[[put-component-template-api-query-params]]
==== {api-query-parms-title}

`create`::
(Optional, boolean)
If `true`, this request cannot replace or update existing component templates.
Defaults to `false`.

include::{docdir}/rest-api/common-parms.asciidoc[tag=master-timeout]

[[put-component-template-api-request-body]]
==== {api-request-body-title}

`template`::
(Required, object)
This is the template to be applied, may optionally include a `mappings`,
`settings`, or `aliases` configuration.

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]

`version`::
(Optional, integer)
Version number used to manage component templates externally.
This number is not automatically generated or incremented by {es}.

`_meta`::
(Optional, object)
Optional user metadata about the component template. May have any contents.
This map is not automatically generated by {es}.

[[put-component-template-api-example]]
==== {api-examples-title}

===== Component template with index aliases

You can include <<indices-aliases,index aliases>> in a component template.

[source,console]
--------------------------------------------------
PUT _component_template/template_1
{
"template": {
"settings" : {
"number_of_shards" : 1
},
"aliases" : {
"alias1" : {},
"alias2" : {
"filter" : {
"term" : {"user" : "kimchy" }
},
"routing" : "kimchy"
},
"{index}-alias" : {} <1>
}
}
}
--------------------------------------------------
<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.

[[applying-component-templates]]
===== Applying component templates

Component templates on their own don't apply or interact with indices at all. In order for them to
be effective, they must be used as part of index template's `composed_of` field to take effect. See
the <<indices-templates,index templates>> documentation for more information.

[[component-templates-version]]
===== Component template versioning

You can use the `version` parameter to add an optional version number to a component 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`, replace the template without specifying one.

[source,console]
--------------------------------------------------
PUT /_component_template/template_1
{
"template": {
"settings" : {
"number_of_shards" : 1
}
},
"version": 123
}
--------------------------------------------------

To check the `version`, you can use the <<getting-component-templates,get component template>> API.

[[component-templates-metadata]]
===== Component template metadata

You can use the `_meta` parameter to add optional metadata to a component template. This is a
user-defined map that can contain any data. This data will be stored in the cluster state however,
so keeping it short is preferrable.

The `_meta` parameter is completely optional and not automatically generated by {es}.

To unset `_meta`, replace the template without specifying one.

[source,console]
--------------------------------------------------
PUT /_component_template/template_1
{
"template": {
"settings" : {
"number_of_shards" : 1
}
},
"_meta": {
"description": "set number of shards to one",
"serialization": {
"class": "MyComponentTemplate",
"id": 10
}
}
}
--------------------------------------------------

To check the `_meta`, you can use the <<getting-component-templates,get component template>> API.
2 changes: 1 addition & 1 deletion docs/reference/indices/delete-index-template.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ include::{docdir}/rest-api/common-parms.asciidoc[tag=index-template]
[[delete-template-api-query-params]]
==== {api-query-parms-title}

include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
16 changes: 8 additions & 8 deletions docs/reference/indices/get-index-template.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[indices-get-template]]
[[indices-get-template-v1]]
=== Get index template API
++++
<titleabbrev>Get index template</titleabbrev>
Expand Down Expand Up @@ -33,13 +33,13 @@ GET /_template/template_1
--------------------------------------------------


[[get-template-api-request]]
[[get-template-v1-api-request]]
==== {api-request-title}

`GET /_template/<index-template>`


[[get-template-api-path-params]]
[[get-template-v1-api-path-params]]
==== {api-path-parms-title}

include::{docdir}/rest-api/common-parms.asciidoc[tag=index-template]
Expand All @@ -48,7 +48,7 @@ To return all index templates, omit this parameter
or use a value of `_all` or `*`.


[[get-template-api-query-params]]
[[get-template-v1-api-query-params]]
==== {api-query-parms-title}

include::{docdir}/rest-api/common-parms.asciidoc[tag=flat-settings]
Expand All @@ -60,11 +60,11 @@ include::{docdir}/rest-api/common-parms.asciidoc[tag=local]
include::{docdir}/rest-api/common-parms.asciidoc[tag=master-timeout]


[[get-template-api-example]]
[[get-template-v1-api-example]]
==== {api-examples-title}


[[get-template-api-multiple-ex]]
[[get-template-v1-api-multiple-ex]]
===== Get multiple index templates

[source,console]
Expand All @@ -73,7 +73,7 @@ GET /_template/template_1,template_2
--------------------------------------------------


[[get-template-api-wildcard-ex]]
[[get-template-v1-api-wildcard-ex]]
===== Get index templates using a wildcard expression

[source,console]
Expand All @@ -82,7 +82,7 @@ GET /_template/temp*
--------------------------------------------------


[[get-template-api-all-ex]]
[[get-template-v1-api-all-ex]]
===== Get all index templates

[source,console]
Expand Down
Loading

0 comments on commit 4315a55

Please sign in to comment.