preview-transform.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[preview-transform]]
  4. === Preview {transforms} API
  5. [subs="attributes"]
  6. ++++
  7. <titleabbrev>Preview {transforms}</titleabbrev>
  8. ++++
  9. Previews a {transform}.
  10. beta[]
  11. [[preview-transform-request]]
  12. ==== {api-request-title}
  13. `POST _transform/_preview`
  14. [[preview-transform-prereq]]
  15. ==== {api-prereq-title}
  16. * If the {es} {security-features} are enabled, you must have `manage_transform`
  17. cluster privileges to use this API. The built-in `transform_admin` role has
  18. these privileges. You must also have `read` and `view_index_metadata` privileges
  19. on the source index for the {transform}. For more information, see
  20. <<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. [[preview-transform-request-body]]
  28. ==== {api-request-body-title}
  29. `source`::
  30. (Required, object) The source configuration, which has the following
  31. properties:
  32. `index`:::
  33. (Required, string or array) The _source indices_ for the
  34. {transform}. It can be a single index, an index pattern (for
  35. example, `"myindex*"`), or an array of indices (for example,
  36. `["index1", "index2"]`).
  37. `query`:::
  38. (Optional, object) A query clause that retrieves a subset of data from the
  39. source index. See <<query-dsl>>.
  40. `pivot`::
  41. (Required, object) Defines the pivot function `group by` fields and the
  42. aggregation to reduce the data. See <<transform-pivot>>.
  43. [[preview-transform-response]]
  44. ==== {api-response-body-title}
  45. `preview`::
  46. (array) An array of documents. In particular, they are the JSON
  47. representation of the documents that would be created in the destination index
  48. by the {transform}.
  49. ==== {api-examples-title}
  50. [source,console]
  51. --------------------------------------------------
  52. POST _transform/_preview
  53. {
  54. "source": {
  55. "index": "kibana_sample_data_ecommerce"
  56. },
  57. "pivot": {
  58. "group_by": {
  59. "customer_id": {
  60. "terms": {
  61. "field": "customer_id"
  62. }
  63. }
  64. },
  65. "aggregations": {
  66. "max_price": {
  67. "max": {
  68. "field": "taxful_total_price"
  69. }
  70. }
  71. }
  72. }
  73. }
  74. --------------------------------------------------
  75. // TEST[skip:set up sample data]
  76. The data that is returned for this example is as follows:
  77. [source,js]
  78. ----
  79. {
  80. "preview" : [
  81. {
  82. "max_price" : 171.0,
  83. "customer_id" : "10"
  84. },
  85. {
  86. "max_price" : 233.0,
  87. "customer_id" : "11"
  88. },
  89. {
  90. "max_price" : 200.0,
  91. "customer_id" : "12"
  92. }
  93. ...
  94. ],
  95. "mappings": {
  96. "properties": {
  97. "max_price": {
  98. "type": "double"
  99. },
  100. "customer_id": {
  101. "type": "keyword"
  102. }
  103. }
  104. }
  105. }
  106. ----
  107. // NOTCONSOLE