preview-transform.asciidoc 8.5 KB

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