preview-transform.asciidoc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 `manage_transform`
  16. cluster privileges to use this API. The built-in `transform_admin` role has
  17. these privileges. You must also have `read` and `view_index_metadata` privileges
  18. on the source index for the {transform}. For more information, see
  19. <<security-privileges>> and <<built-in-roles>>.
  20. [[preview-transform-desc]]
  21. ==== {api-description-title}
  22. This API generates a preview of the results that you will get when you run the
  23. <<put-transform,create {transforms} API>> with the same
  24. configuration. It returns a maximum of 100 results. The calculations are based
  25. on all the current data in the source index.
  26. It also generates a list of mappings and settings for the destination index.
  27. If the destination index does not exist when you start a {transform}, these are
  28. the mappings and settings that are used. These values are determined based on
  29. the field types of the source index and the {transform} aggregations.
  30. TIP: There are some <<transform-aggresponse-limitations,limitations>> that
  31. might result in poor mappings. As a work-around, create the destination index
  32. or an index template with your preferred mappings before you start the
  33. {transform}.
  34. [role="child_attributes"]
  35. [[preview-transform-request-body]]
  36. ==== {api-request-body-title}
  37. `description`::
  38. (Optional, string) Free text description of the {transform}.
  39. //Begin dest
  40. `dest`::
  41. (Optional, object)
  42. include::{docdir}/rest-api/common-parms.asciidoc[tag=dest]
  43. +
  44. .Properties of `dest`
  45. [%collapsible%open]
  46. ====
  47. `index`:::
  48. (Optional, string)
  49. include::{docdir}/rest-api/common-parms.asciidoc[tag=dest-index]
  50. `pipeline`:::
  51. (Optional, string)
  52. include::{docdir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  53. ====
  54. //End dest
  55. `frequency`::
  56. (Optional, <<time-units, time units>>)
  57. include::{docdir}/rest-api/common-parms.asciidoc[tag=frequency]
  58. //Begin pivot
  59. `pivot`::
  60. (Required, object)
  61. include::{docdir}/rest-api/common-parms.asciidoc[tag=pivot]
  62. +
  63. .Properties of `pivot`
  64. [%collapsible%open]
  65. ====
  66. `aggregations` or `aggs`:::
  67. (Required, object)
  68. include::{docdir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  69. `group_by`:::
  70. (Required, object)
  71. include::{docdir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  72. `max_page_search_size`:::
  73. (Optional, integer)
  74. include::{docdir}/rest-api/common-parms.asciidoc[tag=pivot-max-page-search-size]
  75. ====
  76. //End pivot
  77. //Begin source
  78. `source`::
  79. (Required, object)
  80. include::{docdir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  81. +
  82. .Properties of `source`
  83. [%collapsible%open]
  84. ====
  85. `index`:::
  86. (Required, string or array)
  87. include::{docdir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  88. `query`:::
  89. (Optional, object)
  90. include::{docdir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  91. ====
  92. //End source
  93. //Begin sync
  94. `sync`::
  95. (Optional, object)
  96. include::{docdir}/rest-api/common-parms.asciidoc[tag=sync]
  97. +
  98. .Properties of `sync`
  99. [%collapsible%open]
  100. ====
  101. //Begin sync.time
  102. `time`:::
  103. (Optional, object)
  104. include::{docdir}/rest-api/common-parms.asciidoc[tag=sync-time]
  105. +
  106. .Properties of `analysis_config`
  107. [%collapsible%open]
  108. =====
  109. `delay`::::
  110. (Optional, <<time-units, time units>>)
  111. include::{docdir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  112. `field`::::
  113. (Optional, string)
  114. include::{docdir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  115. =====
  116. //End sync.time
  117. ====
  118. //End sync
  119. [role="child_attributes"]
  120. [[preview-transform-response]]
  121. ==== {api-response-body-title}
  122. `preview`::
  123. (array) An array of documents. In particular, they are the JSON representation
  124. of the documents that would be created in the destination index by the
  125. {transform}.
  126. //Begin generated_dest_index
  127. `generated_dest_index`::
  128. (object) Contains details about the destination index.
  129. +
  130. .Properties of `generated_dest_index`
  131. [%collapsible%open]
  132. ====
  133. `aliases`:::
  134. (object) The aliases for the destination index.
  135. `mappings`:::
  136. (object) The <<mapping,mappings>> for each document in the destination index.
  137. `settings`:::
  138. (object) The <<index-modules-settings,index settings>> for the destination index.
  139. ====
  140. //End generated_dest_index
  141. ==== {api-examples-title}
  142. [source,console]
  143. --------------------------------------------------
  144. POST _transform/_preview
  145. {
  146. "source": {
  147. "index": "kibana_sample_data_ecommerce"
  148. },
  149. "pivot": {
  150. "group_by": {
  151. "customer_id": {
  152. "terms": {
  153. "field": "customer_id"
  154. }
  155. }
  156. },
  157. "aggregations": {
  158. "max_price": {
  159. "max": {
  160. "field": "taxful_total_price"
  161. }
  162. }
  163. }
  164. }
  165. }
  166. --------------------------------------------------
  167. // TEST[skip:set up sample data]
  168. The data that is returned for this example is as follows:
  169. [source,js]
  170. ----
  171. {
  172. "preview" : [
  173. {
  174. "max_price" : 171.0,
  175. "customer_id" : "10"
  176. },
  177. {
  178. "max_price" : 233.0,
  179. "customer_id" : "11"
  180. },
  181. {
  182. "max_price" : 200.0,
  183. "customer_id" : "12"
  184. }
  185. ...
  186. ],
  187. "generated_dest_index" : {
  188. "mappings" : {
  189. "_meta" : {
  190. "_transform" : {
  191. "transform" : "transform-preview",
  192. "version" : {
  193. "created" : "7.7.0"
  194. },
  195. "creation_date_in_millis" : 1584738236757
  196. },
  197. "created_by" : "transform"
  198. },
  199. "properties" : {
  200. "max_price" : {
  201. "type" : "half_float"
  202. },
  203. "customer_id" : {
  204. "type" : "keyword"
  205. }
  206. }
  207. },
  208. "settings" : {
  209. "index" : {
  210. "number_of_shards" : "1",
  211. "auto_expand_replicas" : "0-1"
  212. }
  213. },
  214. "aliases" : { }
  215. }
  216. }
  217. ----
  218. // NOTCONSOLE