preview-transform.asciidoc 6.7 KB

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