put-transform.asciidoc 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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
  31. structure (known as a {dataframe}). The ID for each document in the {dataframe}
  32. is generated from a hash of the entity, so there is a unique row per entity. For
  33. more information, see <<transforms>>.
  34. When the {transform} is created, a series of validations occur to ensure its
  35. success. For example, there is a check for the existence of the source indices
  36. and a check that the destination index is not part of the source index pattern.
  37. You can use the `defer_validation` parameter to skip these checks.
  38. Deferred validations are always run when the {transform} is started, with the
  39. exception of privilege checks. When {es} {security-features} are enabled, the
  40. {transform} remembers which roles the user that created it had at the time of
  41. creation and uses those same roles. If those roles do not have the required
  42. privileges on the source and destination indices, the {transform} fails when it
  43. attempts unauthorized operations.
  44. IMPORTANT: You must use {kib} or this API to create a {transform}. Do not add 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 retention policy
  119. `retention_policy`::
  120. (Optional, object)
  121. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention]
  122. +
  123. .Properties of `retention_policy`
  124. [%collapsible%open]
  125. ====
  126. `time`:::
  127. (Required, object)
  128. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time]
  129. +
  130. .Properties of `time`
  131. [%collapsible%open]
  132. =====
  133. `field`:::
  134. (Required, string)
  135. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-field]
  136. `max_age`:::
  137. (Required, <<time-units, time units>>)
  138. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-max-age]
  139. =====
  140. ====
  141. //End retention policy
  142. //Begin settings
  143. `settings`::
  144. (Optional, object)
  145. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  146. +
  147. .Properties of `settings`
  148. [%collapsible%open]
  149. ====
  150. `dates_as_epoch_millis`:::
  151. (Optional, boolean)
  152. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-dates-as-epoch-milli]
  153. `docs_per_second`:::
  154. (Optional, float)
  155. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  156. `max_page_search_size`:::
  157. (Optional, integer)
  158. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  159. ====
  160. //End settings
  161. //Begin source
  162. `source`::
  163. (Required, object)
  164. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  165. +
  166. .Properties of `source`
  167. [%collapsible%open]
  168. ====
  169. `index`:::
  170. (Required, string or array)
  171. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  172. `query`:::
  173. (Optional, object)
  174. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  175. `runtime_mappings`:::
  176. (Optional, object)
  177. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-runtime-mappings-transforms]
  178. ====
  179. //End source
  180. //Begin sync
  181. `sync`::
  182. (Optional, object)
  183. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  184. +
  185. .Properties of `sync`
  186. [%collapsible%open]
  187. ====
  188. //Begin time
  189. `time`:::
  190. (Required, object)
  191. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  192. +
  193. .Properties of `time`
  194. [%collapsible%open]
  195. =====
  196. `delay`::::
  197. (Optional, <<time-units, time units>>)
  198. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  199. `field`::::
  200. (Required, string)
  201. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  202. +
  203. --
  204. TIP: In general, it’s a good idea to use a field that contains the
  205. <<access-ingest-metadata,ingest timestamp>>. If you use a different field,
  206. you might need to set the `delay` such that it accounts for data transmission
  207. delays.
  208. --
  209. =====
  210. //End time
  211. ====
  212. //End sync
  213. [[put-transform-example]]
  214. == {api-examples-title}
  215. The following {transform} uses the `pivot` method:
  216. [source,console]
  217. --------------------------------------------------
  218. PUT _transform/ecommerce_transform1
  219. {
  220. "source": {
  221. "index": "kibana_sample_data_ecommerce",
  222. "query": {
  223. "term": {
  224. "geoip.continent_name": {
  225. "value": "Asia"
  226. }
  227. }
  228. }
  229. },
  230. "pivot": {
  231. "group_by": {
  232. "customer_id": {
  233. "terms": {
  234. "field": "customer_id"
  235. }
  236. }
  237. },
  238. "aggregations": {
  239. "max_price": {
  240. "max": {
  241. "field": "taxful_total_price"
  242. }
  243. }
  244. }
  245. },
  246. "description": "Maximum priced ecommerce data by customer_id in Asia",
  247. "dest": {
  248. "index": "kibana_sample_data_ecommerce_transform1",
  249. "pipeline": "add_timestamp_pipeline"
  250. },
  251. "frequency": "5m",
  252. "sync": {
  253. "time": {
  254. "field": "order_date",
  255. "delay": "60s"
  256. }
  257. },
  258. "retention_policy": {
  259. "time": {
  260. "field": "order_date",
  261. "max_age": "30d"
  262. }
  263. }
  264. }
  265. --------------------------------------------------
  266. // TEST[setup:kibana_sample_data_ecommerce,add_timestamp_pipeline]
  267. When the {transform} is created, you receive the following results:
  268. [source,console-result]
  269. ----
  270. {
  271. "acknowledged" : true
  272. }
  273. ----
  274. The following {transform} uses the `latest` method:
  275. [source,console]
  276. --------------------------------------------------
  277. PUT _transform/ecommerce_transform2
  278. {
  279. "source": {
  280. "index": "kibana_sample_data_ecommerce"
  281. },
  282. "latest": {
  283. "unique_key": ["customer_id"],
  284. "sort": "order_date"
  285. },
  286. "description": "Latest order for each customer",
  287. "dest": {
  288. "index": "kibana_sample_data_ecommerce_transform2"
  289. },
  290. "frequency": "5m",
  291. "sync": {
  292. "time": {
  293. "field": "order_date",
  294. "delay": "60s"
  295. }
  296. }
  297. }
  298. --------------------------------------------------
  299. // TEST[setup:kibana_sample_data_ecommerce]