put-transform.asciidoc 9.1 KB

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