downsample-data-stream.asciidoc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. [role="xpack"]
  2. [[indices-downsample-data-stream]]
  3. === Downsample index API
  4. ++++
  5. <titleabbrev>Downsample</titleabbrev>
  6. ++++
  7. preview::[]
  8. Aggregates a time series (TSDS) index and stores
  9. pre-computed statistical summaries (`min`, `max`, `sum`, `value_count` and
  10. `avg`) for each metric field grouped by a configured time interval. For example,
  11. a TSDS index that contains metrics sampled every 10 seconds can be downsampled
  12. to an hourly index. All documents within an hour interval are summarized and
  13. stored as a single document in the downsample index.
  14. ////
  15. [source,console]
  16. ----
  17. PUT /my-time-series-index
  18. {
  19. "settings": {
  20. "index": {
  21. "mode": "time_series",
  22. "time_series": {
  23. "start_time": "2022-06-10T00:00:00Z",
  24. "end_time": "2022-06-30T23:59:59Z"
  25. },
  26. "routing_path": [
  27. "test.namespace"
  28. ],
  29. "number_of_replicas": 0,
  30. "number_of_shards": 2
  31. }
  32. },
  33. "mappings": {
  34. "properties": {
  35. "@timestamp": {
  36. "type": "date"
  37. },
  38. "metric": {
  39. "type": "long",
  40. "time_series_metric": "gauge"
  41. },
  42. "dimension": {
  43. "type": "keyword",
  44. "time_series_dimension": true
  45. }
  46. }
  47. }
  48. }
  49. PUT /my-time-series-index/_block/write
  50. ----
  51. // TEST
  52. ////
  53. [source,console]
  54. ----
  55. POST /my-time-series-index/_downsample/my-downsampled-time-series-index
  56. {
  57. "fixed_interval": "1d"
  58. }
  59. ----
  60. // TEST[continued]
  61. ////
  62. [source,console]
  63. ----
  64. DELETE /my-time-series-index*
  65. DELETE _data_stream/*
  66. DELETE _index_template/*
  67. ----
  68. // TEST[continued]
  69. ////
  70. [[downsample-api-request]]
  71. ==== {api-request-title}
  72. `POST /<source-index>/_downsample/<output-downsampled-index>`
  73. [[downsample-api-prereqs]]
  74. ==== {api-prereq-title}
  75. * Only indices in a <<tsds,time series data stream>> are supported.
  76. * If the {es} {security-features} are enabled, you must have the `all`
  77. or `manage` <<privileges-list-indices,index privilege>> for the data stream.
  78. * Neither <<field-and-document-access-control,field nor document level security>> can be defined on the source index.
  79. * The source index must be read only (`index.blocks.write: true`).
  80. [[downsample-api-path-params]]
  81. ==== {api-path-parms-title}
  82. `<source-index>`::
  83. (Optional, string) Name of the time series index to downsample.
  84. `<output-downsampled_index>`::
  85. +
  86. --
  87. (Required, string) Name of the index to create.
  88. include::{es-repo-dir}/indices/create-index.asciidoc[tag=index-name-reqs]
  89. --
  90. [role="child_attributes"]
  91. [[downsample-api-query-parms]]
  92. ==== {api-query-parms-title}
  93. `fixed_interval`:: (Required, <<time-units,time units>>) The interval at which
  94. to aggregate the original time series index. For example, `60m` produces a
  95. document for each 60 minute (hourly) interval. This follows standard time
  96. formatting syntax as used elsewhere in {es}.
  97. +
  98. NOTE: Smaller, more granular intervals take up proportionally more space.
  99. [[downsample-api-process]]
  100. ==== The downsampling process
  101. The downsampling operation traverses the source TSDS index and performs the
  102. following steps:
  103. . Creates a new document for each value of the `_tsid` field and each
  104. `@timestamp` value, rounded to the `fixed_interval` defined in the downsample
  105. configuration.
  106. . For each new document, copies all <<time-series-dimension,time
  107. series dimensions>> from the source index to the target index. Dimensions in a
  108. TSDS are constant, so this is done only once per bucket.
  109. . For each <<time-series-metric,time series metric>> field, computes aggregations
  110. for all documents in the bucket. Depending on the metric type of each metric
  111. field a different set of pre-aggregated results is stored:
  112. ** `gauge`: The `min`, `max`, `sum`, and `value_count` are stored; `value_count`
  113. is stored as type `aggregate_metric_double`.
  114. ** `counter`: The `last_value` is stored.
  115. . For all other fields, the most recent value is copied to the target index.
  116. [[downsample-api-mappings]]
  117. ==== Source and target index field mappings
  118. Fields in the target, downsampled index are created based on fields in the
  119. original source index, as follows:
  120. . All fields mapped with the `time-series-dimension` parameter are created in
  121. the target downsample index with the same mapping as in the source index.
  122. . All fields mapped with the `time_series_metric` parameter are created
  123. in the target downsample index with the same mapping as in the source
  124. index. An exception is that for fields mapped as `time_series_metric: gauge`
  125. the field type is changed to `aggregate_metric_double`.
  126. . All other fields that are neither dimensions nor metrics (that is, label
  127. fields), are created in the target downsample index with the same mapping
  128. that they had in the source index.
  129. Check the <<downsampling,Downsampling>> documentation for an overview and
  130. examples of running downsampling manually and as part of an ILM policy.