simulate-multi-component-templates.asciidoc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. [[simulate-multi-component-templates]]
  2. == Simulate multi-component templates
  3. Since templates can be composed not only of multiple component templates, but also the index
  4. template itself, there are two simulation APIs to determine what the resulting index settings will
  5. be.
  6. To simulate the settings that would be applied to a particular index name:
  7. ////
  8. [source,console]
  9. --------------------------------------------------
  10. PUT /_index_template/template_1
  11. {
  12. "index_patterns" : ["my*"],
  13. "priority" : 1,
  14. "template": {
  15. "settings" : {
  16. "number_of_shards" : 2
  17. }
  18. }
  19. }
  20. --------------------------------------------------
  21. // TESTSETUP
  22. [source,console]
  23. --------------------------------------------------
  24. DELETE /_index_template/template_1
  25. --------------------------------------------------
  26. // TEARDOWN
  27. ////
  28. [source,console]
  29. --------------------------------------------------
  30. POST /_index_template/_simulate_index/my-index-000001
  31. --------------------------------------------------
  32. To simulate the settings that would be applied from an existing template:
  33. [source,console]
  34. --------------------------------------------------
  35. POST /_index_template/_simulate/template_1
  36. --------------------------------------------------
  37. You can also specify a template definition in the simulate request.
  38. This enables you to verify that settings will be applied as expected before you add a new template.
  39. [source,console]
  40. --------------------------------------------------
  41. PUT /_component_template/ct1
  42. {
  43. "template": {
  44. "settings": {
  45. "index.number_of_shards": 2
  46. }
  47. }
  48. }
  49. PUT /_component_template/ct2
  50. {
  51. "template": {
  52. "settings": {
  53. "index.number_of_replicas": 0
  54. },
  55. "mappings": {
  56. "properties": {
  57. "@timestamp": {
  58. "type": "date"
  59. }
  60. }
  61. }
  62. }
  63. }
  64. POST /_index_template/_simulate
  65. {
  66. "index_patterns": ["my*"],
  67. "template": {
  68. "settings" : {
  69. "index.number_of_shards" : 3
  70. }
  71. },
  72. "composed_of": ["ct1", "ct2"]
  73. }
  74. --------------------------------------------------
  75. The response shows the settings, mappings, and aliases that would be applied to matching indices,
  76. and any overlapping templates whose configuration would be superseded by the simulated template body
  77. or higher-priority templates.
  78. [source,console-result]
  79. ---------------------------------------------------------
  80. {
  81. "template" : {
  82. "settings" : {
  83. "index" : {
  84. "number_of_shards" : "3", <1>
  85. "number_of_replicas" : "0"
  86. }
  87. },
  88. "mappings" : {
  89. "properties" : {
  90. "@timestamp" : {
  91. "type" : "date" <2>
  92. }
  93. }
  94. },
  95. "aliases" : { }
  96. },
  97. "overlapping" : [
  98. {
  99. "name" : "template_1", <3>
  100. "index_patterns" : [
  101. "my*"
  102. ]
  103. }
  104. ]
  105. }
  106. ---------------------------------------------------------
  107. <1> The number of shards from the simulated template body
  108. <2> The `@timestamp` field inherited from the `ct2` component template
  109. <3> Any overlapping templates that would have matched, but have lower priority