put-transform.asciidoc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[put-transform]]
  4. === Create {transform} API
  5. [subs="attributes"]
  6. ++++
  7. <titleabbrev>Create {transform}</titleabbrev>
  8. ++++
  9. Instantiates a {transform}.
  10. [[put-transform-request]]
  11. ==== {api-request-title}
  12. `PUT _transform/<transform_id>`
  13. [[put-transform-prereqs]]
  14. ==== {api-prereq-title}
  15. If the {es} {security-features} are enabled, you must have the following
  16. built-in roles and privileges:
  17. * `transform_admin`
  18. * `kibana_admin` (UI only)
  19. * source index: `read`, `view_index_metadata`
  20. * destination index: `read`, `create_index`, `manage` and `index`
  21. * cluster: `monitor` (UI only)
  22. For more information, see <<security-privileges>> and <<built-in-roles>>.
  23. [[put-transform-desc]]
  24. ==== {api-description-title}
  25. This API defines a {transform}, which copies data from source indices,
  26. transforms it, and persists it into an entity-centric destination index. The
  27. entities are defined by the set of `group_by` fields in the `pivot` object. You
  28. can also think of the destination index as a two-dimensional tabular data
  29. structure (known as a {dataframe}). The ID for each document in the
  30. {dataframe} is generated from a hash of the entity, so there is a unique row
  31. per entity. For more information, see <<transforms>>.
  32. When the {transform} is created, a series of validations occur to
  33. ensure its success. For example, there is a check for the existence of the
  34. source indices and a check that the destination index is not part of the source
  35. index pattern. You can use the `defer_validation` parameter to skip these
  36. checks.
  37. Deferred validations are always run when the {transform} is started,
  38. with the exception of privilege checks. When {es} {security-features} are
  39. enabled, the {transform} remembers which roles the user that created
  40. it had at the time of creation and uses those same roles. If those roles do not
  41. have the required privileges on the source and destination indices, the
  42. {transform} fails when it attempts unauthorized operations.
  43. IMPORTANT: You must use {kib} or this API to create a {transform}.
  44. Do not put a {transform} directly into any
  45. `.transform-internal*` indices using the Elasticsearch index API.
  46. If {es} {security-features} are enabled, do not give users any
  47. privileges on `.transform-internal*` indices. If you used transforms
  48. prior 7.5, also do not give users any privileges on
  49. `.data-frame-internal*` indices.
  50. [[put-transform-path-parms]]
  51. ==== {api-path-parms-title}
  52. `<transform_id>`::
  53. (Required, string)
  54. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-id]
  55. [[put-transform-query-parms]]
  56. ==== {api-query-parms-title}
  57. `defer_validation`::
  58. (Optional, boolean) When `true`, deferrable validations are not run. This
  59. behavior may be desired if the source index does not exist until after the
  60. {transform} is created.
  61. [role="child_attributes"]
  62. [[put-transform-request-body]]
  63. ==== {api-request-body-title}
  64. `description`::
  65. (Optional, string) Free text description of the {transform}.
  66. //Begin dest
  67. `dest`::
  68. (Required, object)
  69. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest]
  70. +
  71. .Properties of `dest`
  72. [%collapsible%open]
  73. ====
  74. `index`:::
  75. (Required, string)
  76. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-index]
  77. `pipeline`:::
  78. (Optional, string)
  79. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  80. ====
  81. //End dest
  82. `frequency`::
  83. (Optional, <<time-units, time units>>)
  84. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=frequency]
  85. //Begin pivot
  86. `pivot`::
  87. (Required, object)
  88. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot]
  89. +
  90. .Properties of `pivot`
  91. [%collapsible%open]
  92. ====
  93. `aggregations` or `aggs`:::
  94. (Required, object)
  95. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  96. `group_by`:::
  97. (Required, object)
  98. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  99. ====
  100. //End pivot
  101. //Begin settings
  102. `settings`::
  103. (Optional, object)
  104. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  105. +
  106. .Properties of `settings`
  107. [%collapsible%open]
  108. ====
  109. `docs_per_second`:::
  110. (Optional, float)
  111. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  112. `max_page_search_size`:::
  113. (Optional, integer)
  114. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  115. ====
  116. //End settings
  117. //Begin source
  118. `source`::
  119. (Required, object)
  120. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  121. +
  122. .Properties of `source`
  123. [%collapsible%open]
  124. ====
  125. `index`:::
  126. (Required, string or array)
  127. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  128. `query`:::
  129. (Optional, object)
  130. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  131. ====
  132. //End source
  133. //Begin sync
  134. `sync`::
  135. (Optional, object)
  136. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  137. +
  138. .Properties of `sync`
  139. [%collapsible%open]
  140. ====
  141. //Begin time
  142. `time`:::
  143. (Required, object)
  144. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  145. +
  146. .Properties of `time`
  147. [%collapsible%open]
  148. =====
  149. `delay`::::
  150. (Optional, <<time-units, time units>>)
  151. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  152. `field`::::
  153. (Required, string)
  154. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  155. +
  156. --
  157. TIP: In general, it’s a good idea to use a field that contains the
  158. <<accessing-ingest-metadata,ingest timestamp>>. If you use a different field,
  159. you might need to set the `delay` such that it accounts for data transmission
  160. delays.
  161. --
  162. =====
  163. //End time
  164. ====
  165. //End sync
  166. [[put-transform-example]]
  167. ==== {api-examples-title}
  168. [source,console]
  169. --------------------------------------------------
  170. PUT _transform/ecommerce_transform
  171. {
  172. "source": {
  173. "index": "kibana_sample_data_ecommerce",
  174. "query": {
  175. "term": {
  176. "geoip.continent_name": {
  177. "value": "Asia"
  178. }
  179. }
  180. }
  181. },
  182. "pivot": {
  183. "group_by": {
  184. "customer_id": {
  185. "terms": {
  186. "field": "customer_id"
  187. }
  188. }
  189. },
  190. "aggregations": {
  191. "max_price": {
  192. "max": {
  193. "field": "taxful_total_price"
  194. }
  195. }
  196. }
  197. },
  198. "description": "Maximum priced ecommerce data by customer_id in Asia",
  199. "dest": {
  200. "index": "kibana_sample_data_ecommerce_transform",
  201. "pipeline": "add_timestamp_pipeline"
  202. },
  203. "frequency": "5m",
  204. "sync": {
  205. "time": {
  206. "field": "order_date",
  207. "delay": "60s"
  208. }
  209. }
  210. }
  211. --------------------------------------------------
  212. // TEST[setup:kibana_sample_data_ecommerce,add_timestamp_pipeline]
  213. When the {transform} is created, you receive the following results:
  214. [source,console-result]
  215. ----
  216. {
  217. "acknowledged" : true
  218. }
  219. ----