index-templates.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. When a composable template matches a given index
  19. it always takes precedence over a legacy template. If no composable template matches, a legacy
  20. template may still match and be applied.
  21. If an index is created with explicit settings and also matches an index template,
  22. the settings from the create index request take precedence over settings specified in the index template and its component templates.
  23. [source,console]
  24. --------------------------------------------------
  25. PUT _component_template/component_template1
  26. {
  27. "template": {
  28. "mappings": {
  29. "properties": {
  30. "@timestamp": {
  31. "type": "date"
  32. }
  33. }
  34. }
  35. }
  36. }
  37. PUT _component_template/other_component_template
  38. {
  39. "template": {
  40. "mappings": {
  41. "properties": {
  42. "ip_address": {
  43. "type": "ip"
  44. }
  45. }
  46. }
  47. }
  48. }
  49. PUT _index_template/template_1
  50. {
  51. "index_patterns": ["te*", "bar*"],
  52. "template": {
  53. "settings": {
  54. "number_of_shards": 1
  55. },
  56. "mappings": {
  57. "_source": {
  58. "enabled": false
  59. },
  60. "properties": {
  61. "host_name": {
  62. "type": "keyword"
  63. },
  64. "created_at": {
  65. "type": "date",
  66. "format": "EEE MMM dd HH:mm:ss Z yyyy"
  67. }
  68. }
  69. },
  70. "aliases": {
  71. "mydata": { }
  72. }
  73. },
  74. "priority": 10,
  75. "composed_of": ["component_template1", "other_component_template"],
  76. "version": 3,
  77. "_meta": {
  78. "description": "my custom"
  79. }
  80. }
  81. --------------------------------------------------
  82. // TESTSETUP
  83. ////
  84. [source,console]
  85. --------------------------------------------------
  86. DELETE _index_template/*
  87. DELETE _component_template/*
  88. --------------------------------------------------
  89. // TEARDOWN
  90. ////
  91. include::simulate-multi-component-templates.asciidoc[]