preview-transform.asciidoc 5.7 KB

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