time-series-aggregation.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. [[search-aggregations-bucket-time-series-aggregation]]
  2. === Time series aggregation
  3. ++++
  4. <titleabbrev>Time series</titleabbrev>
  5. ++++
  6. preview::[]
  7. The time series aggregation queries data created using a <<tsds,Time series data stream (TSDS)>>. This is typically data such as metrics
  8. or other data streams with a time component, and requires creating an index using the time series mode.
  9. [NOTE]
  10. ====
  11. Refer to the <<differences-from-regular-data-stream, TSDS documentation>> to learn more about the key differences from regular data streams.
  12. ====
  13. //////////////////////////
  14. Creating a time series mapping
  15. To create an index with the time series mapping, specify "mode" as "time_series" in the index settings,
  16. "routing_path" specifying the a list of time series fields, and a start and end time for the series. Each of the
  17. "routing_path" fields must be keyword fields with "time_series_dimension" set to true. Additionally, add a
  18. date field used as the timestamp.
  19. [source,js]
  20. --------------------------------------------------
  21. PUT /my-time-series-index
  22. {
  23. "settings": {
  24. "index": {
  25. "number_of_shards": 3,
  26. "number_of_replicas": 2,
  27. "mode": "time_series",
  28. "routing_path": ["key"],
  29. "time_series": {
  30. "start_time": "2022-01-01T00:00:00Z",
  31. "end_time": "2023-01-01T00:00:00Z"
  32. }
  33. }
  34. },
  35. "mappings": {
  36. "properties": {
  37. "key": {
  38. "type": "keyword",
  39. "time_series_dimension": true
  40. },
  41. "@timestamp": {
  42. "type": "date"
  43. }
  44. }
  45. }
  46. }
  47. -------------------------------------------------
  48. // NOTCONSOLE
  49. //////////////////////////
  50. Data can be added to the time series index like other indices:
  51. [source,js]
  52. --------------------------------------------------
  53. PUT /my-time-series-index-0/_bulk
  54. { "index": {} }
  55. { "key": "a", "val": 1, "@timestamp": "2022-01-01T00:00:10Z" }
  56. { "index": {}}
  57. { "key": "a", "val": 2, "@timestamp": "2022-01-02T00:00:00Z" }
  58. { "index": {} }
  59. { "key": "b", "val": 2, "@timestamp": "2022-01-01T00:00:10Z" }
  60. { "index": {}}
  61. { "key": "b", "val": 3, "@timestamp": "2022-01-02T00:00:00Z" }
  62. --------------------------------------------------
  63. // NOTCONSOLE
  64. To perform a time series aggregation, specify "time_series" as the aggregation type. When the boolean "keyed"
  65. is true, each bucket is given a unique key.
  66. [source,js,id=time-series-aggregation-example]
  67. --------------------------------------------------
  68. GET /_search
  69. {
  70. "aggs": {
  71. "ts": {
  72. "time_series": { "keyed": false }
  73. }
  74. }
  75. }
  76. --------------------------------------------------
  77. // NOTCONSOLE
  78. This will return all results in the time series, however a more typical query will use sub aggregations to reduce the
  79. date returned to something more relevant.
  80. [[search-aggregations-bucket-time-series-aggregation-size]]
  81. ==== Size
  82. By default, `time series` aggregations return 10000 results. The "size" parameter can be used to limit the results
  83. further. Alternatively, using sub aggregations can limit the amount of values returned as a time series aggregation.
  84. [[search-aggregations-bucket-time-series-aggregation-keyed]]
  85. ==== Keyed
  86. The `keyed` parameter determines if buckets are returned as a map with unique keys per bucket. By default with `keyed`
  87. set to false, buckets are returned as an array.
  88. [[times-series-aggregations-limitations]]
  89. ==== Limitations
  90. The `time_series` aggregation has many limitations. Many aggregation performance optimizations are disabled when using
  91. the `time_series` aggregation. For example the filter by filter optimization or collect mode breath first (`terms` and
  92. `multi_terms` aggregation forcefully use the depth first collect mode).
  93. The following aggregations also fail to work if used in combination with the `time_series` aggregation:
  94. `auto_date_histogram`, `variable_width_histogram`, `rare_terms`, `global`, `composite`, `sampler`, `random_sampler` and
  95. `diversified_sampler`.