simulate-template.asciidoc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. [[indices-simulate-template]]
  2. === Simulate index template API
  3. ++++
  4. <titleabbrev>Simulate template</titleabbrev>
  5. ++++
  6. Returns the index configuration that would be applied by a particular
  7. <<index-templates, index template>>.
  8. ////
  9. [source,console]
  10. --------------------------------------------------
  11. PUT _index_template/template_1
  12. {
  13. "index_patterns": ["te*", "bar*"],
  14. "template": {
  15. "settings": {
  16. "number_of_shards": 1
  17. },
  18. "mappings": {
  19. "_source": {
  20. "enabled": false
  21. },
  22. "properties": {
  23. "host_name": {
  24. "type": "keyword"
  25. },
  26. "created_at": {
  27. "type": "date",
  28. "format": "EEE MMM dd HH:mm:ss Z yyyy"
  29. }
  30. }
  31. },
  32. "aliases": {
  33. "mydata": { }
  34. }
  35. },
  36. "priority": 10,
  37. "version": 3,
  38. "_meta": {
  39. "description": "my custom"
  40. }
  41. }
  42. --------------------------------------------------
  43. // TESTSETUP
  44. [source,console]
  45. --------------------------------------------------
  46. DELETE _index_template/*
  47. --------------------------------------------------
  48. // TEARDOWN
  49. ////
  50. [source,console]
  51. --------------------------------------------------
  52. POST /_index_template/_simulate/template_1
  53. --------------------------------------------------
  54. [[simulate-template-api-request]]
  55. ==== {api-request-title}
  56. `POST /_index_template/_simulate/<index-template>`
  57. [[simulate-template-api-prereqs]]
  58. ==== {api-prereq-title}
  59. * If the {es} {security-features} are enabled, you must have the
  60. `manage_index_templates` or `manage` <<privileges-list-cluster,cluster
  61. privilege>> to use this API.
  62. [[simulate-template-api-path-params]]
  63. ==== {api-path-parms-title}
  64. `<index-template>`::
  65. (Optional, string)
  66. Name of the index template to simulate.
  67. To test a template configuration before you add it to the cluster,
  68. omit this parameter and specify the template configuration in the request body.
  69. [[simulate-template-api-query-params]]
  70. ==== {api-query-parms-title}
  71. ////
  72. `cause`::
  73. (Optional, string) The reason for using the specified template for the simulation.
  74. ////
  75. `create`::
  76. (Optional, Boolean) If `true`, the template passed in the body is
  77. only used if no existing templates match the same index patterns.
  78. If `false`, the simulation uses the template with the highest priority.
  79. Note that the template is not permanently added or updated in either case;
  80. it is only used for the simulation.
  81. Defaults to `false`.
  82. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
  83. [role="child_attributes"]
  84. [[simulate-template-api-request-body]]
  85. ==== {api-request-body-title}
  86. include::{es-ref-dir}/indices/put-index-template.asciidoc[tag=index-template-api-body]
  87. [role="child_attributes"]
  88. [[simulate-template-api-response-body]]
  89. ==== {api-response-body-title}
  90. `overlapping`::
  91. (array) Any templates that were superseded by the specified template.
  92. +
  93. .Properties of `overlapping`
  94. [%collapsible%open]
  95. ====
  96. `index_patterns`::
  97. (array) Index patterns that the superseded template applies to.
  98. `name`::
  99. (string) Name of the superseded template.
  100. ====
  101. `template`::
  102. (object)
  103. The settings, mappings, and aliases that would be applied to matching indices.
  104. +
  105. .Properties of `template`
  106. [%collapsible%open]
  107. ====
  108. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=aliases]
  109. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=mappings]
  110. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=settings]
  111. ====
  112. [[simulate-template-api-example]]
  113. ==== {api-examples-title}
  114. [[simulate-existing-template-ex]]
  115. ===== Simulating an existing template
  116. The following example creates and simulates a composed template:
  117. [source,console]
  118. --------------------------------------------------
  119. PUT /_component_template/ct1 <1>
  120. {
  121. "template": {
  122. "settings": {
  123. "index.number_of_shards": 2
  124. }
  125. }
  126. }
  127. PUT /_component_template/ct2 <2>
  128. {
  129. "template": {
  130. "settings": {
  131. "index.number_of_replicas": 0
  132. },
  133. "mappings": {
  134. "properties": {
  135. "@timestamp": {
  136. "type": "date"
  137. }
  138. }
  139. }
  140. }
  141. }
  142. PUT /_index_template/final-template <3>
  143. {
  144. "index_patterns": ["my-index-*"],
  145. "composed_of": ["ct1", "ct2"],
  146. "priority": 5
  147. }
  148. POST /_index_template/_simulate/final-template <4>
  149. --------------------------------------------------
  150. <1> Create a component template (`ct1`) that sets the number of shards to 2
  151. <2> Create a component template (`ct2`) that sets the number of replicas to 0 and defines a mapping
  152. <3> Create an index template (`final-template`) that uses the component templates
  153. <4> Show the configuration applied by the `final-template`
  154. The response shows the index settings, mappings, and aliases applied by the `final-template`:
  155. [source,console-result]
  156. ---------------------------------------------------------
  157. {
  158. "template" : {
  159. "settings" : {
  160. "index" : {
  161. "number_of_shards" : "2", <1>
  162. "number_of_replicas" : "0" <2>
  163. }
  164. },
  165. "mappings" : { <3>
  166. "properties" : {
  167. "@timestamp" : {
  168. "type" : "date"
  169. }
  170. }
  171. },
  172. "aliases" : { }
  173. },
  174. "overlapping" : [ ]
  175. }
  176. ---------------------------------------------------------
  177. <1> Number of shards from `ct1`
  178. <2> Number of replicas from `ct2`
  179. <3> Mappings from `ct1`
  180. [[simulate-template-config-ex]]
  181. ===== Simulating an arbitrary template configuration
  182. To see what settings will be applied by a template before you add it to the cluster,
  183. you can pass a template configuration in the request body.
  184. The specified template is used for the simulation if it has a higher priority than existing templates.
  185. [source,console]
  186. --------------------------------------------------
  187. POST /_index_template/_simulate
  188. {
  189. "index_patterns": ["my-index-*"],
  190. "composed_of": ["ct2"],
  191. "priority": 10,
  192. "template": {
  193. "settings": {
  194. "index.number_of_replicas": 1
  195. }
  196. }
  197. }
  198. --------------------------------------------------
  199. // TEST[continued]
  200. The response shows any overlapping templates with a lower priority.
  201. [source,console-result]
  202. ---------------------------------------------------------
  203. {
  204. "template" : {
  205. "settings" : {
  206. "index" : {
  207. "number_of_replicas" : "1"
  208. }
  209. },
  210. "mappings" : {
  211. "properties" : {
  212. "@timestamp" : {
  213. "type" : "date"
  214. }
  215. }
  216. },
  217. "aliases" : { }
  218. },
  219. "overlapping" : [
  220. {
  221. "name" : "final-template",
  222. "index_patterns" : [
  223. "my-index-*"
  224. ]
  225. }
  226. ]
  227. }
  228. ---------------------------------------------------------