put-transform.asciidoc 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. [role="xpack"]
  2. [[put-transform]]
  3. = Create {transform} API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Create {transform}</titleabbrev>
  7. ++++
  8. Instantiates a {transform}.
  9. [[put-transform-request]]
  10. == {api-request-title}
  11. `PUT _transform/<transform_id>`
  12. [[put-transform-prereqs]]
  13. == {api-prereq-title}
  14. Requires the following privileges:
  15. * cluster: `manage_transform` (the `transform_admin` built-in role grants this
  16. privilege)
  17. * source indices: `read`, `view_index_metadata`
  18. * destination index: `read`, `create_index`, `index`. If a `retention_policy` is configured, the `delete` privilege is
  19. also required.
  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. Identifier for the {transform}. This identifier can contain lowercase
  54. alphanumeric characters (a-z and 0-9), hyphens, and underscores. It has a 64
  55. character limit and must start and end with alphanumeric characters.
  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. `timeout`::
  63. (Optional, time)
  64. Period to wait for a response. If no response is received before the timeout
  65. expires, the request fails and returns an error. Defaults to `30s`.
  66. [role="child_attributes"]
  67. [[put-transform-request-body]]
  68. == {api-request-body-title}
  69. `description`::
  70. (Optional, string) Free text description of the {transform}.
  71. //Begin dest
  72. `dest`::
  73. (Required, object)
  74. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest]
  75. +
  76. .Properties of `dest`
  77. [%collapsible%open]
  78. ====
  79. `index`:::
  80. (Required, string)
  81. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-index]
  82. `pipeline`:::
  83. (Optional, string)
  84. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  85. ====
  86. //End dest
  87. `frequency`::
  88. (Optional, <<time-units, time units>>)
  89. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=frequency]
  90. //Begin latest
  91. `latest`::
  92. (Required^*^, object)
  93. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-latest]
  94. +
  95. .Properties of `latest`
  96. [%collapsible%open]
  97. ====
  98. `sort`:::
  99. (Required, string)
  100. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-sort]
  101. `unique_key`:::
  102. (Required, array of strings)
  103. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-unique-key]
  104. ====
  105. //End latest
  106. //Begin _meta
  107. `_meta`::
  108. (Optional, object)
  109. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-metadata]
  110. //End _meta
  111. //Begin pivot
  112. `pivot`::
  113. (Required^*^, object)
  114. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot]
  115. +
  116. .Properties of `pivot`
  117. [%collapsible%open]
  118. ====
  119. `aggregations` or `aggs`:::
  120. (Required, object)
  121. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  122. `group_by`:::
  123. (Required, object)
  124. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  125. ====
  126. //End pivot
  127. //Begin retention policy
  128. `retention_policy`::
  129. (Optional, object)
  130. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention]
  131. +
  132. .Properties of `retention_policy`
  133. [%collapsible%open]
  134. ====
  135. `time`:::
  136. (Required, object)
  137. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time]
  138. +
  139. .Properties of `time`
  140. [%collapsible%open]
  141. =====
  142. `field`:::
  143. (Required, string)
  144. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-field]
  145. `max_age`:::
  146. (Required, <<time-units, time units>>)
  147. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-max-age]
  148. =====
  149. ====
  150. //End retention policy
  151. //Begin settings
  152. `settings`::
  153. (Optional, object)
  154. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  155. +
  156. .Properties of `settings`
  157. [%collapsible%open]
  158. ====
  159. `dates_as_epoch_millis`:::
  160. (Optional, boolean)
  161. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-dates-as-epoch-milli]
  162. `docs_per_second`:::
  163. (Optional, float)
  164. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  165. `align_checkpoints`:::
  166. (Optional, boolean)
  167. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-align-checkpoints]
  168. `deduce_mappings`:::
  169. (Optional, boolean)
  170. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-deduce-mappings]
  171. `max_page_search_size`:::
  172. (Optional, integer)
  173. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  174. ====
  175. //End settings
  176. //Begin source
  177. `source`::
  178. (Required, object)
  179. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  180. +
  181. .Properties of `source`
  182. [%collapsible%open]
  183. ====
  184. `index`:::
  185. (Required, string or array)
  186. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  187. `query`:::
  188. (Optional, object)
  189. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  190. `runtime_mappings`:::
  191. (Optional, object)
  192. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-runtime-mappings-transforms]
  193. ====
  194. //End source
  195. //Begin sync
  196. `sync`::
  197. (Optional, object)
  198. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  199. +
  200. .Properties of `sync`
  201. [%collapsible%open]
  202. ====
  203. //Begin time
  204. `time`:::
  205. (Required, object)
  206. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  207. +
  208. .Properties of `time`
  209. [%collapsible%open]
  210. =====
  211. `delay`::::
  212. (Optional, <<time-units, time units>>)
  213. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  214. `field`::::
  215. (Required, string)
  216. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  217. +
  218. --
  219. TIP: In general, it’s a good idea to use a field that contains the
  220. <<access-ingest-metadata,ingest timestamp>>. If you use a different field,
  221. you might need to set the `delay` such that it accounts for data transmission
  222. delays.
  223. --
  224. =====
  225. //End time
  226. ====
  227. //End sync
  228. [[put-transform-example]]
  229. == {api-examples-title}
  230. The following {transform} uses the `pivot` method:
  231. [source,console]
  232. --------------------------------------------------
  233. PUT _transform/ecommerce_transform1
  234. {
  235. "source": {
  236. "index": "kibana_sample_data_ecommerce",
  237. "query": {
  238. "term": {
  239. "geoip.continent_name": {
  240. "value": "Asia"
  241. }
  242. }
  243. }
  244. },
  245. "pivot": {
  246. "group_by": {
  247. "customer_id": {
  248. "terms": {
  249. "field": "customer_id"
  250. }
  251. }
  252. },
  253. "aggregations": {
  254. "max_price": {
  255. "max": {
  256. "field": "taxful_total_price"
  257. }
  258. }
  259. }
  260. },
  261. "description": "Maximum priced ecommerce data by customer_id in Asia",
  262. "dest": {
  263. "index": "kibana_sample_data_ecommerce_transform1",
  264. "pipeline": "add_timestamp_pipeline"
  265. },
  266. "frequency": "5m",
  267. "sync": {
  268. "time": {
  269. "field": "order_date",
  270. "delay": "60s"
  271. }
  272. },
  273. "retention_policy": {
  274. "time": {
  275. "field": "order_date",
  276. "max_age": "30d"
  277. }
  278. }
  279. }
  280. --------------------------------------------------
  281. // TEST[setup:kibana_sample_data_ecommerce,add_timestamp_pipeline]
  282. When the {transform} is created, you receive the following results:
  283. [source,console-result]
  284. ----
  285. {
  286. "acknowledged" : true
  287. }
  288. ----
  289. The following {transform} uses the `latest` method:
  290. [source,console]
  291. --------------------------------------------------
  292. PUT _transform/ecommerce_transform2
  293. {
  294. "source": {
  295. "index": "kibana_sample_data_ecommerce"
  296. },
  297. "latest": {
  298. "unique_key": ["customer_id"],
  299. "sort": "order_date"
  300. },
  301. "description": "Latest order for each customer",
  302. "dest": {
  303. "index": "kibana_sample_data_ecommerce_transform2"
  304. },
  305. "frequency": "5m",
  306. "sync": {
  307. "time": {
  308. "field": "order_date",
  309. "delay": "60s"
  310. }
  311. }
  312. }
  313. --------------------------------------------------
  314. // TEST[setup:kibana_sample_data_ecommerce]