preview-transform.asciidoc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. [role="child_attributes"]
  38. [[preview-transform-path-params]]
  39. == {api-path-parms-title}
  40. `<transform_id>`::
  41. (Optional, string)
  42. Id of the {transform} to preview.
  43. +
  44. NOTE: If you provide the `<transform_id>` as a path parameter, you cannot
  45. provide {transform} configuration details in the request body.
  46. [[preview-transform-request-body]]
  47. == {api-request-body-title}
  48. `description`::
  49. (Optional, string) Free text description of the {transform}.
  50. //Begin dest
  51. `dest`::
  52. (Optional, object)
  53. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest]
  54. +
  55. .Properties of `dest`
  56. [%collapsible%open]
  57. ====
  58. `index`:::
  59. (Optional, string)
  60. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-index]
  61. `pipeline`:::
  62. (Optional, string)
  63. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  64. ====
  65. //End dest
  66. `frequency`::
  67. (Optional, <<time-units, time units>>)
  68. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=frequency]
  69. //Begin latest
  70. `latest`::
  71. (Required^*^, object)
  72. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-latest]
  73. +
  74. .Properties of `latest`
  75. [%collapsible%open]
  76. ====
  77. `sort`:::
  78. (Required, string)
  79. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-sort]
  80. `unique_key`:::
  81. (Required, array of strings)
  82. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-unique-key]
  83. ====
  84. //End latest
  85. //Begin pivot
  86. `pivot`::
  87. (Required, object)
  88. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot]
  89. +
  90. .Properties of `pivot`
  91. [%collapsible%open]
  92. ====
  93. `aggregations` or `aggs`:::
  94. (Required, object)
  95. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  96. `group_by`:::
  97. (Required, object)
  98. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  99. ====
  100. //End pivot
  101. //Begin retention policy
  102. `retention_policy`::
  103. (Optional, object)
  104. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention]
  105. +
  106. .Properties of `retention_policy`
  107. [%collapsible%open]
  108. ====
  109. `time`:::
  110. (Required, object)
  111. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time]
  112. +
  113. .Properties of `time`
  114. [%collapsible%open]
  115. =====
  116. `field`:::
  117. (Required, string)
  118. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-field]
  119. `max_age`:::
  120. (Required, <<time-units, time units>>)
  121. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-max-age]
  122. =====
  123. ====
  124. //End retention policy
  125. //Begin source
  126. `source`::
  127. (Required, object)
  128. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  129. +
  130. .Properties of `source`
  131. [%collapsible%open]
  132. ====
  133. `index`:::
  134. (Required, string or array)
  135. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  136. `query`:::
  137. (Optional, object)
  138. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  139. `runtime_mappings`:::
  140. (Optional, object)
  141. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-runtime-mappings-transforms]
  142. ====
  143. //End source
  144. //Begin sync
  145. `sync`::
  146. (Optional, object)
  147. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  148. +
  149. .Properties of `sync`
  150. [%collapsible%open]
  151. ====
  152. //Begin sync.time
  153. `time`:::
  154. (Optional, object)
  155. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  156. +
  157. .Properties of `analysis_config`
  158. [%collapsible%open]
  159. =====
  160. `delay`::::
  161. (Optional, <<time-units, time units>>)
  162. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  163. `field`::::
  164. (Optional, string)
  165. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  166. =====
  167. //End sync.time
  168. ====
  169. //End sync
  170. //Begin settings
  171. `settings`::
  172. (Optional, object)
  173. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  174. +
  175. .Properties of `settings`
  176. [%collapsible%open]
  177. ====
  178. `docs_per_second`:::
  179. (Optional, float)
  180. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  181. `align_checkpoints`:::
  182. (Optional, boolean)
  183. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-align-checkpoints]
  184. `max_page_search_size`:::
  185. (Optional, integer)
  186. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  187. ====
  188. //End settings
  189. [role="child_attributes"]
  190. [[preview-transform-response]]
  191. == {api-response-body-title}
  192. `preview`::
  193. (array) An array of documents. In particular, they are the JSON representation
  194. of the documents that would be created in the destination index by the
  195. {transform}.
  196. //Begin generated_dest_index
  197. `generated_dest_index`::
  198. (object) Contains details about the destination index.
  199. +
  200. .Properties of `generated_dest_index`
  201. [%collapsible%open]
  202. ====
  203. `aliases`:::
  204. (object) The aliases for the destination index.
  205. `mappings`:::
  206. (object) The <<mapping,mappings>> for each document in the destination index.
  207. `settings`:::
  208. (object) The <<index-modules-settings,index settings>> for the destination index.
  209. ====
  210. //End generated_dest_index
  211. == {api-examples-title}
  212. [source,console]
  213. --------------------------------------------------
  214. POST _transform/_preview
  215. {
  216. "source": {
  217. "index": "kibana_sample_data_ecommerce"
  218. },
  219. "pivot": {
  220. "group_by": {
  221. "customer_id": {
  222. "terms": {
  223. "field": "customer_id"
  224. }
  225. }
  226. },
  227. "aggregations": {
  228. "max_price": {
  229. "max": {
  230. "field": "taxful_total_price"
  231. }
  232. }
  233. }
  234. }
  235. }
  236. --------------------------------------------------
  237. // TEST[skip:set up sample data]
  238. The data that is returned for this example is as follows:
  239. [source,js]
  240. ----
  241. {
  242. "preview" : [
  243. {
  244. "max_price" : 171.0,
  245. "customer_id" : "10"
  246. },
  247. {
  248. "max_price" : 233.0,
  249. "customer_id" : "11"
  250. },
  251. {
  252. "max_price" : 200.0,
  253. "customer_id" : "12"
  254. }
  255. ...
  256. ],
  257. "generated_dest_index" : {
  258. "mappings" : {
  259. "_meta" : {
  260. "_transform" : {
  261. "transform" : "transform-preview",
  262. "version" : {
  263. "created" : "7.7.0"
  264. },
  265. "creation_date_in_millis" : 1584738236757
  266. },
  267. "created_by" : "transform"
  268. },
  269. "properties" : {
  270. "max_price" : {
  271. "type" : "half_float"
  272. },
  273. "customer_id" : {
  274. "type" : "keyword"
  275. }
  276. }
  277. },
  278. "settings" : {
  279. "index" : {
  280. "number_of_shards" : "1",
  281. "auto_expand_replicas" : "0-1"
  282. }
  283. },
  284. "aliases" : { }
  285. }
  286. }
  287. ----
  288. // NOTCONSOLE