preview-transform.asciidoc 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. [role="xpack"]
  2. [[preview-transform]]
  3. = Preview {transform} API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Preview {transform}</titleabbrev>
  7. ++++
  8. Previews a {transform}.
  9. [[preview-transform-request]]
  10. == {api-request-title}
  11. `GET _transform/<transform_id>/_preview` +
  12. `POST _transform/<transform_id>/_preview` +
  13. `GET _transform/_preview` +
  14. `POST _transform/_preview`
  15. [[preview-transform-prereq]]
  16. == {api-prereq-title}
  17. Requires the following privileges:
  18. * cluster: `manage_transform` (the `transform_admin` built-in role grants this
  19. privilege)
  20. * source indices: `read`, `view_index_metadata`.
  21. [[preview-transform-desc]]
  22. == {api-description-title}
  23. This API generates a preview of the results that you will get when you run the
  24. <<put-transform,create {transforms} API>> with the same
  25. configuration. It returns a maximum of 100 results. The calculations are based
  26. on all the current data in the source index.
  27. It also generates a list of mappings and settings for the destination index.
  28. If the destination index does not exist when you start a {transform}, these are
  29. the mappings and settings that are used. These values are determined based on
  30. the field types of the source index and the {transform} aggregations.
  31. TIP: There are some <<transform-aggresponse-limitations,limitations>> that
  32. might result in poor mappings. As a work-around, create the destination index
  33. or an index template with your preferred mappings before you start the
  34. {transform}.
  35. You must choose either the `latest` or `pivot` method for your {transform}; you
  36. cannot use both in a single {transform}.
  37. IMPORTANT: When you preview a {transform}, it uses the credentials of the user
  38. calling the API. When you start a {transform}, it uses the roles of the last
  39. user to create or update it. If the two sets of roles differ, the preview may
  40. not accurately reflect the behavior of the {transform}. To avoid such problems,
  41. the same user that creates or updates the {transform} should preview it to
  42. ensure it is returning the expected data. Alternatively, use
  43. <<http-clients-secondary-authorization,secondary authorization headers>> to
  44. supply the credentials
  45. [role="child_attributes"]
  46. [[preview-transform-path-params]]
  47. == {api-path-parms-title}
  48. `<transform_id>`::
  49. (Optional, string)
  50. Id of the {transform} to preview.
  51. +
  52. NOTE: If you provide the `<transform_id>` as a path parameter, you cannot
  53. provide {transform} configuration details in the request body.
  54. [[preview-transform-query-parms]]
  55. == {api-query-parms-title}
  56. `timeout`::
  57. (Optional, time)
  58. Period to wait for a response. If no response is received before the timeout
  59. expires, the request fails and returns an error. Defaults to `30s`.
  60. [[preview-transform-request-body]]
  61. == {api-request-body-title}
  62. `description`::
  63. (Optional, string) Free text description of the {transform}.
  64. //Begin dest
  65. `dest`::
  66. (Optional, object)
  67. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest]
  68. +
  69. .Properties of `dest`
  70. [%collapsible%open]
  71. ====
  72. `index`:::
  73. (Optional, string)
  74. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-index]
  75. `pipeline`:::
  76. (Optional, string)
  77. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  78. ====
  79. //End dest
  80. `frequency`::
  81. (Optional, <<time-units, time units>>)
  82. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=frequency]
  83. //Begin latest
  84. `latest`::
  85. (Required^*^, object)
  86. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-latest]
  87. +
  88. .Properties of `latest`
  89. [%collapsible%open]
  90. ====
  91. `sort`:::
  92. (Required, string)
  93. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-sort]
  94. `unique_key`:::
  95. (Required, array of strings)
  96. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-unique-key]
  97. ====
  98. //End latest
  99. //Begin pivot
  100. `pivot`::
  101. (Required, object)
  102. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot]
  103. +
  104. .Properties of `pivot`
  105. [%collapsible%open]
  106. ====
  107. `aggregations` or `aggs`:::
  108. (Required, object)
  109. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  110. `group_by`:::
  111. (Required, object)
  112. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  113. ====
  114. //End pivot
  115. //Begin retention policy
  116. `retention_policy`::
  117. (Optional, object)
  118. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention]
  119. +
  120. .Properties of `retention_policy`
  121. [%collapsible%open]
  122. ====
  123. `time`:::
  124. (Required, object)
  125. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time]
  126. +
  127. .Properties of `time`
  128. [%collapsible%open]
  129. =====
  130. `field`:::
  131. (Required, string)
  132. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-field]
  133. `max_age`:::
  134. (Required, <<time-units, time units>>)
  135. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-max-age]
  136. =====
  137. ====
  138. //End retention policy
  139. //Begin source
  140. `source`::
  141. (Required, object)
  142. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  143. +
  144. .Properties of `source`
  145. [%collapsible%open]
  146. ====
  147. `index`:::
  148. (Required, string or array)
  149. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  150. `query`:::
  151. (Optional, object)
  152. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  153. `runtime_mappings`:::
  154. (Optional, object)
  155. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-runtime-mappings-transforms]
  156. ====
  157. //End source
  158. //Begin sync
  159. `sync`::
  160. (Optional, object)
  161. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  162. +
  163. .Properties of `sync`
  164. [%collapsible%open]
  165. ====
  166. //Begin sync.time
  167. `time`:::
  168. (Optional, object)
  169. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  170. +
  171. .Properties of `time`
  172. [%collapsible%open]
  173. =====
  174. `delay`::::
  175. (Optional, <<time-units, time units>>)
  176. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  177. `field`::::
  178. (Optional, string)
  179. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  180. =====
  181. //End sync.time
  182. ====
  183. //End sync
  184. //Begin settings
  185. `settings`::
  186. (Optional, object)
  187. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  188. +
  189. .Properties of `settings`
  190. [%collapsible%open]
  191. ====
  192. `align_checkpoints`:::
  193. (Optional, boolean)
  194. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-align-checkpoints]
  195. `dates_as_epoch_millis`:::
  196. (Optional, boolean)
  197. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-dates-as-epoch-milli]
  198. `deduce_mappings`:::
  199. (Optional, boolean)
  200. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-deduce-mappings]
  201. `docs_per_second`:::
  202. (Optional, float)
  203. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  204. `max_page_search_size`:::
  205. (Optional, integer)
  206. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  207. `unattended`:::
  208. (Optional, boolean)
  209. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-unattended]
  210. ====
  211. //End settings
  212. [role="child_attributes"]
  213. [[preview-transform-response]]
  214. == {api-response-body-title}
  215. //Begin generated_dest_index
  216. `generated_dest_index`::
  217. (object) Contains details about the destination index.
  218. +
  219. .Properties of `generated_dest_index`
  220. [%collapsible%open]
  221. ====
  222. `aliases`:::
  223. (object) The aliases for the destination index.
  224. `mappings`:::
  225. (object) The <<mapping,mappings>> for each document in the destination index.
  226. `settings`:::
  227. (object) The <<index-modules-settings,index settings>> for the destination index.
  228. ====
  229. //End generated_dest_index
  230. `preview`::
  231. (array) An array of documents. In particular, they are the JSON representation
  232. of the documents that would be created in the destination index by the
  233. {transform}.
  234. == {api-examples-title}
  235. [source,console]
  236. --------------------------------------------------
  237. POST _transform/_preview
  238. {
  239. "source": {
  240. "index": "kibana_sample_data_ecommerce"
  241. },
  242. "pivot": {
  243. "group_by": {
  244. "customer_id": {
  245. "terms": {
  246. "field": "customer_id",
  247. "missing_bucket": true
  248. }
  249. }
  250. },
  251. "aggregations": {
  252. "max_price": {
  253. "max": {
  254. "field": "taxful_total_price"
  255. }
  256. }
  257. }
  258. }
  259. }
  260. --------------------------------------------------
  261. // TEST[skip:set up sample data]
  262. The data that is returned for this example is as follows:
  263. [source,js]
  264. ----
  265. {
  266. "preview" : [
  267. {
  268. "max_price" : 171.0,
  269. "customer_id" : "10"
  270. },
  271. {
  272. "max_price" : 233.0,
  273. "customer_id" : "11"
  274. },
  275. {
  276. "max_price" : 200.0,
  277. "customer_id" : "12"
  278. }
  279. ...
  280. ],
  281. "generated_dest_index" : {
  282. "mappings" : {
  283. "_meta" : {
  284. "_transform" : {
  285. "transform" : "transform-preview",
  286. "version" : {
  287. "created" : "7.7.0"
  288. },
  289. "creation_date_in_millis" : 1584738236757
  290. },
  291. "created_by" : "transform"
  292. },
  293. "properties" : {
  294. "max_price" : {
  295. "type" : "half_float"
  296. },
  297. "customer_id" : {
  298. "type" : "keyword"
  299. }
  300. }
  301. },
  302. "settings" : {
  303. "index" : {
  304. "number_of_shards" : "1",
  305. "auto_expand_replicas" : "0-1"
  306. }
  307. },
  308. "aliases" : { }
  309. }
  310. }
  311. ----
  312. // NOTCONSOLE