preview-transform.asciidoc 7.5 KB

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