preview-transform.asciidoc 6.7 KB

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