elasticsearch/docs/reference/data-streams/lifecycle/apis/get-lifecycle.asciidoc
Mary Gouseti 91f4023e27
Expose global retention settings via data stream lifecycle API (#112210)
In this PR we expose the global retention via the `GET
_data_stream/{target}/_lifecycle` API.

Since the global retention is a main feature of the data stream
lifecycle we chose to expose it by default.

```
GET /_data_stream/my-data-stream/_lifecycle
{
 "global_retention": {
      "default_retention": "7d",
      "max_retention": "365d"
  }, 
  "data_streams": [...]
}
```
2024-09-02 18:40:08 +10:00

173 lines
5.2 KiB
Text

[[data-streams-get-lifecycle]]
=== Get the lifecycle of a data stream
++++
<titleabbrev>Get Data Stream Lifecycle</titleabbrev>
++++
Gets the <<data-stream-lifecycle,lifecycle>> of a set of <<data-streams,data streams>>.
[[get-lifecycle-api-prereqs]]
==== {api-prereq-title}
* If the {es} {security-features} are enabled, you must have at least one of the `manage`
<<privileges-list-indices,index privilege>>, the `manage_data_stream_lifecycle` index privilege, or the
`view_index_metadata` privilege to use this API. For more information, see <<security-privileges>>.
[[data-streams-get-lifecycle-request]]
==== {api-request-title}
`GET _data_stream/<data-stream>/_lifecycle`
[[data-streams-get-lifecycle-desc]]
==== {api-description-title}
Gets the lifecycle of the specified data streams. If multiple data streams are requested but at least one of them
does not exist, then the API will respond with `404` since at least one of the requested resources could not be retrieved.
If the requested data streams do not have a lifecycle configured they will still be included in the API response but the
`lifecycle` key will be missing.
[[data-streams-get-lifecycle-path-params]]
==== {api-path-parms-title}
`<data-stream>`::
(Required, string) Comma-separated list of data streams used to limit the request. Supports wildcards (`*`).
To target all data streams use `*` or `_all`.
[role="child_attributes"]
[[get-data-lifecycle-api-query-parms]]
==== {api-query-parms-title}
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=ds-expand-wildcards]
+
Defaults to `open`.
`include_defaults`::
(Optional, Boolean) If `true`, return all default settings in the response.
Defaults to `false`.
[role="child_attributes"]
[[get-lifecycle-api-response-body]]
==== {api-response-body-title}
`data_streams`::
(array of objects)
Contains information about retrieved data stream lifecycles.
+
.Properties of objects in `data_streams`
[%collapsible%open]
====
`name`::
(string)
Name of the data stream.
`lifecycle`::
(Optional, object)
+
.Properties of `lifecycle`
[%collapsible%open]
=====
`data_retention`::
(Optional, string)
If defined, it represents the retention requested by the data stream owner for this data stream.
`effective_retention`::
(Optional, string)
If defined, every document added to this data stream will be stored at least for this time frame. Any time after this
duration the document could be deleted. When empty, every document in this data stream will be stored indefinitely.
duration the document could be deleted. When empty, every document in this data stream will be stored indefinitely. The
effective retention is calculated as described in the <<effective-retention-calculation, tutorial>>.
`retention_determined_by`::
(Optional, string)
The source of the retention, it can be one of three values, `data_stream_configuration`, `default_retention` or `max_retention`.
`rollover`::
(Optional, object)
The conditions which will trigger the rollover of a backing index as configured by the cluster setting
`cluster.lifecycle.default.rollover`. This property is an implementation detail and it will only be retrieved
when the query param `include_defaults` is set to `true`. The contents of this field are subject to change.
=====
====
`global_retention`::
(object)
Contains the global max and default retention. When no global retention is configured, this will be an empty object.
+
.Properties of `global_retention`
[%collapsible%open]
====
`max_retention`::
(Optional, string)
The effective retention of data streams managed by the data stream lifecycle cannot exceed this value.
`default_retention`::
(Optional, string)
This will be the effective retention of data streams managed by the data stream lifecycle that do not specify `data_retention`.
====
[[data-streams-get-lifecycle-example]]
==== {api-examples-title}
////
[source,console]
--------------------------------------------------
PUT /_index_template/my-template
{
"index_patterns" : ["my-data-stream*"],
"priority" : 1,
"data_stream": {},
"template": {
"lifecycle" : {
"data_retention" : "7d"
}
}
}
PUT /_data_stream/my-data-stream-1
PUT /_data_stream/my-data-stream-2
--------------------------------------------------
// TESTSETUP
[source,console]
--------------------------------------------------
DELETE _data_stream/my-data-stream*
DELETE _index_template/my-template
--------------------------------------------------
// TEARDOWN
////
Let's retrieve the lifecycles:
[source,console]
--------------------------------------------------
GET _data_stream/my-data-stream*/_lifecycle
--------------------------------------------------
The response will look like the following:
[source,console-result]
--------------------------------------------------
{
"data_streams": [
{
"name": "my-data-stream-1",
"lifecycle": {
"enabled": true,
"data_retention": "7d",
"effective_retention": "7d",
"retention_determined_by": "data_stream_configuration"
}
},
{
"name": "my-data-stream-2",
"lifecycle": {
"enabled": true,
"data_retention": "7d",
"effective_retention": "7d",
"retention_determined_by": "data_stream_configuration"
}
}
],
"global_retention": {}
}
--------------------------------------------------