index-templates.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. [[index-templates]]
  2. = Index templates
  3. NOTE: This topic describes the composable index templates introduced in {es} 7.8.
  4. For information about how index templates worked previously,
  5. see the <<indices-templates-v1,legacy template documentation>>.
  6. [[getting]]
  7. An index template is a way to tell {es} how to configure an index when it is created.
  8. For data streams, the index template configures the stream's backing indices as they
  9. are created. Templates are configured prior to index creation and then when an
  10. index is created either manually or through indexing a document, the template
  11. settings are used as a basis for creating the index.
  12. There are two types of templates, index templates and <<indices-component-template,component
  13. templates>>. Component templates are reusable building blocks that configure mappings, settings, and
  14. aliases. You use component templates to construct index templates, they aren't directly applied to a
  15. set of indices. Index templates can contain a collection of component templates, as well as directly
  16. specify settings, mappings, and aliases.
  17. If a new data stream or index matches more than one index template, the index template with the highest priority is used.
  18. // tag::built-in-index-templates[]
  19. [IMPORTANT]
  20. ====
  21. {es} has built-in index templates for the `metrics-*-*`, `logs-*-*`, and
  22. `synthetics-*-*` index patterns, each with a priority of `100`. The
  23. {fleet-guide}/fleet-overview.html[{agent}] uses these templates to create data
  24. streams. If you use the {agent}, assign your index templates a priority lower
  25. than `100` to avoid overriding the built-in templates.
  26. Otherwise, to avoid accidentally applying the built-in templates, use a
  27. non-overlapping index pattern or assign templates with an overlapping pattern a
  28. `priority` higher than `100`.
  29. For example, if you don't use the {agent} and want to create a template for the
  30. `logs-*` index pattern, assign your template a priority of `200`. This ensures
  31. your template is applied instead of the built-in template for `logs-*-*`.
  32. ====
  33. // end::built-in-index-templates[]
  34. When a composable template matches a given index
  35. it always takes precedence over a legacy template. If no composable template matches, a legacy
  36. template may still match and be applied.
  37. If an index is created with explicit settings and also matches an index template,
  38. the settings from the create index request take precedence over settings specified in the index template and its component templates.
  39. [source,console]
  40. --------------------------------------------------
  41. PUT _component_template/component_template1
  42. {
  43. "template": {
  44. "mappings": {
  45. "properties": {
  46. "@timestamp": {
  47. "type": "date"
  48. }
  49. }
  50. }
  51. }
  52. }
  53. PUT _component_template/other_component_template
  54. {
  55. "template": {
  56. "mappings": {
  57. "properties": {
  58. "ip_address": {
  59. "type": "ip"
  60. }
  61. }
  62. }
  63. }
  64. }
  65. PUT _index_template/template_1
  66. {
  67. "index_patterns": ["te*", "bar*"],
  68. "template": {
  69. "settings": {
  70. "number_of_shards": 1
  71. },
  72. "mappings": {
  73. "_source": {
  74. "enabled": false
  75. },
  76. "properties": {
  77. "host_name": {
  78. "type": "keyword"
  79. },
  80. "created_at": {
  81. "type": "date",
  82. "format": "EEE MMM dd HH:mm:ss Z yyyy"
  83. }
  84. }
  85. },
  86. "aliases": {
  87. "mydata": { }
  88. }
  89. },
  90. "priority": 200,
  91. "composed_of": ["component_template1", "other_component_template"],
  92. "version": 3,
  93. "_meta": {
  94. "description": "my custom"
  95. }
  96. }
  97. --------------------------------------------------
  98. // TESTSETUP
  99. ////
  100. [source,console]
  101. --------------------------------------------------
  102. DELETE _index_template/*
  103. DELETE _component_template/*
  104. --------------------------------------------------
  105. // TEARDOWN
  106. ////
  107. include::simulate-multi-component-templates.asciidoc[]