put-transform.asciidoc 8.1 KB

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