Skip to content

Commit 3ccc767

Browse files
committed
Expand docs for component template merging. (#59466)
This change clarifies the order in which components are merged. It also adds information on mapping merging, now that this has been implemented.
1 parent c30d382 commit 3ccc767

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

docs/reference/indices/index-templates.asciidoc

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ This is the template to be applied, may optionally include a `mappings`,
332332
`composed_of`::
333333
(Optional, array of strings)
334334
An ordered list of component template names. Component templates are merged in the order
335-
specified, meaning that the last component template specified has the highest precedence. See
335+
specified, meaning that the last component template specified has the highest precedence. See
336336
<<multiple-component-templates,Composing multiple component templates>> for an example.
337337

338338
`priority`::
@@ -507,13 +507,15 @@ PUT /_index_template/template_1
507507
--------------------------------------------------
508508

509509
[[multiple-component-templates]]
510-
===== Composing multiple component templates
510+
===== Composing aliases, mappings, and settings
511511

512512
When multiple component templates are specified in the `composed_of` field for an index template,
513513
they are merged in the order specified, meaning that later component templates override earlier
514-
component templates.
514+
component templates. Any mappings, settings, or aliases from the parent index template are merged
515+
in next. Finally, any configuration on the index request itself is merged.
515516

516-
For two component templates, the order they are specified changes the number of shards for an index:
517+
In this example, the order of the two component templates changes the number of shards for an
518+
index:
517519

518520
[source,console]
519521
--------------------------------------------------
@@ -545,6 +547,16 @@ PUT /_index_template/template_1
545547
In this case, an index matching `t*` will have three primary shards. If the order of composed
546548
templates were reversed, the index would have two primary shards.
547549

550+
Mapping definitions are merged recursively, which means that later mapping components can
551+
introduce new field mappings and update the mapping configuration. If a field mapping is
552+
already contained in an earlier component, its definition will be completely overwritten
553+
by the later one.
554+
555+
This recursive merging strategy applies not only to field mappings, but also root options like
556+
`dynamic_templates` and `meta`. If an earlier component contains a `dynamic_templates` block,
557+
then by default new `dynamic_templates` entries are appended onto the end. If an entry already
558+
exists with the same key, then it is overwritten by the new definition.
559+
548560
[[indices-get-template]]
549561
=== Get index template API [[getting-templates]]
550562
++++
@@ -601,4 +613,4 @@ GET /_index_template/temp*
601613
[source,console]
602614
--------------------------------------------------
603615
GET /_index_template
604-
--------------------------------------------------
616+
--------------------------------------------------

0 commit comments

Comments
 (0)