put-transform.asciidoc 9.0 KB

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