put-lifecycle.asciidoc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. [[data-streams-put-lifecycle]]
  2. === Set the lifecycle of a data stream
  3. ++++
  4. <titleabbrev>Put Data Stream Lifecycle</titleabbrev>
  5. ++++
  6. .New API reference
  7. [sidebar]
  8. --
  9. For the most up-to-date API details, refer to {api-es}/group/endpoint-data-stream[Data stream APIs].
  10. --
  11. Configures the data stream <<data-stream-lifecycle,lifecycle>> for the targeted <<data-streams,data streams>>.
  12. [[put-lifecycle-api-prereqs]]
  13. ==== {api-prereq-title}
  14. If the {es} {security-features} are enabled, you must have the `manage_data_stream_lifecycle` index privilege or higher to use this API.
  15. For more information, see <<security-privileges>>.
  16. [[data-streams-put-lifecycle-request]]
  17. ==== {api-request-title}
  18. `PUT _data_stream/<data-stream>/_lifecycle`
  19. [[data-streams-put-lifecycle-desc]]
  20. ==== {api-description-title}
  21. Configures the data stream lifecycle for the targeted data streams. If multiple data streams are provided but at least one of them
  22. does not exist, then the update of the lifecycle will fail for all of them and the API will respond with `404`.
  23. [[data-streams-put-lifecycle-path-params]]
  24. ==== {api-path-parms-title}
  25. `<data-stream>`::
  26. (Required, string) Comma-separated list of data streams used to limit the request. Supports wildcards (`*`).
  27. To target all data streams use `*` or `_all`.
  28. [role="child_attributes"]
  29. [[put-data-lifecycle-api-query-parms]]
  30. ==== {api-query-parms-title}
  31. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=ds-expand-wildcards]
  32. +
  33. Defaults to `open`.
  34. [[put-lifecycle-api-request-body]]
  35. ==== {api-request-body-title}
  36. `lifecycle`::
  37. (Required, object)
  38. +
  39. .Properties of `lifecycle`
  40. [%collapsible%open]
  41. ====
  42. `data_retention`::
  43. (Optional, string)
  44. If defined, every document added to this data stream will be stored at least for this time frame. Any time after this
  45. duration the document could be deleted. When empty, every document in this data stream will be stored indefinitely.
  46. `enabled`::
  47. (Optional, boolean)
  48. If defined, it turns data stream lifecycle on/off (`true`/`false`) for this data stream.
  49. A data stream lifecycle that's disabled (`enabled: false`) will have no effect on the
  50. data stream. Defaults to `true`.
  51. `downsampling`::
  52. (Optional, array)
  53. An optional array of downsampling configuration objects, each defining an `after`
  54. interval representing when the backing index is meant to be downsampled (the time
  55. frame is calculated since the index was rolled over, i.e. generation time) and
  56. a `fixed_interval` representing the downsampling interval (the minimum `fixed_interval`
  57. value is `5m`). A maximum number of 10 downsampling rounds can be configured.
  58. See <<data-streams-put-lifecycle-downsampling-example, configuration example>> below.
  59. ====
  60. [[data-streams-put-lifecycle-example]]
  61. ==== {api-examples-title}
  62. The following example sets the lifecycle of `my-data-stream`:
  63. [source,console]
  64. --------------------------------------------------
  65. PUT _data_stream/my-data-stream/_lifecycle
  66. {
  67. "data_retention": "7d"
  68. }
  69. --------------------------------------------------
  70. // TEST[setup:my_data_stream]
  71. // TEST[teardown:data_stream_cleanup]
  72. When the lifecycle is successfully updated in all data streams, you receive the following result:
  73. [source,console-result]
  74. --------------------------------------------------
  75. {
  76. "acknowledged": true
  77. }
  78. --------------------------------------------------
  79. [[data-streams-put-lifecycle-downsampling-example]]
  80. ==== {api-examples-title}
  81. The following example configures two downsampling rounds, the first one starting
  82. one day after the backing index is rolled over (or later, if the index is still
  83. within its write-accepting <<time-bound-indices, time bounds>>) with an interval
  84. of `10m`, and a second round starting 7 days after rollover at an interval of `1d`:
  85. [source,console]
  86. --------------------------------------------------------------------
  87. PUT _data_stream/my-weather-sensor-data-stream/_lifecycle
  88. {
  89. "downsampling": [
  90. {
  91. "after": "1d",
  92. "fixed_interval": "10m"
  93. },
  94. {
  95. "after": "7d",
  96. "fixed_interval": "1d"
  97. }
  98. ]
  99. }
  100. --------------------------------------------------------------------
  101. //TEST[skip:downsampling requires waiting for indices to be out of time bounds]