|
| 1 | +# 获取数据流的生命周期 |
| 2 | + |
| 3 | +获取一组[数据流](/data-streams)的[生命周期](/data-streams/data-stream-lifecycle)。 |
| 4 | + |
| 5 | +## 前置条件 |
| 6 | + |
| 7 | +- 如果 Elasticsearch 安全特性启用,你使用此 API 必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限) 或 `manage_data_stream_lifecycle` 索引权限或 `view_index_metadata` 索引权限。更多信息,参阅[安全权限](/secure_the_elastic_statck/user_authorization/security_privileges)。 |
| 8 | + |
| 9 | +## 请求 |
| 10 | + |
| 11 | +`GET _data_stream/<data-stream>/_lifecycle` |
| 12 | + |
| 13 | +## 描述 |
| 14 | + |
| 15 | +获取指定数据流的生命周期。如果请求多个数据流,但其中至少有一个不存在,那么 API 将以 404 响应,因为至少有一个请求的资源无法检索。如果请求的数据流没有配置生命周期,它们仍将包含在 API 响应中,但 `lifecycle` 关键字将丢失。 |
| 16 | + |
| 17 | +## 路径参数 |
| 18 | + |
| 19 | +- `<data-stream>` |
| 20 | + |
| 21 | + (必需,字符串) 用于限制请求的数据流的逗号分隔列表。支持通配符 (`*`)。要针对所有数据流,请使用 `*` 或 `_all`。 |
| 22 | + |
| 23 | +## 查询参数 |
| 24 | + |
| 25 | +- `expand_wildcards` |
| 26 | + |
| 27 | + (可选,字符串)通配符模式可以匹配的数据流类型。支持逗号分隔值,例如 `open,hidden`。有效值为: |
| 28 | + |
| 29 | + - `all`,`hidden` |
| 30 | + |
| 31 | + 匹配任何数据流或索引,包括[隐藏的](/rest_apis/api_conventions/multi_target_syntax#隐藏数据流和索引)。 |
| 32 | + |
| 33 | + - `open`,`closed` |
| 34 | + |
| 35 | + 匹配任何非隐藏的数据流。无法关闭 Data Streams。 |
| 36 | + |
| 37 | + - `none` |
| 38 | + |
| 39 | + 不接受通配符模式。 |
| 40 | + |
| 41 | + 默认为 `open`。 |
| 42 | + |
| 43 | +- `include_defaults` |
| 44 | + |
| 45 | + (可选,布尔值) 如果为 `true`,则在响应中返回所有默认设置。默认为 `false`。 |
| 46 | + |
| 47 | +## 响应体 |
| 48 | + |
| 49 | +- `data_streams` |
| 50 | + |
| 51 | + (对象数组)包含有关检索到的数据流生命周期的信息。 |
| 52 | + |
| 53 | + - `data_streams` 对象属性 |
| 54 | + |
| 55 | + - `name` |
| 56 | + |
| 57 | + (字符串) 数据流的名称。 |
| 58 | + |
| 59 | + - `lifecycle` |
| 60 | + |
| 61 | + (可选,对象) |
| 62 | + |
| 63 | + `lifecycle` 属性 |
| 64 | + |
| 65 | + - `data_retention` |
| 66 | + |
| 67 | + (可选,字符串) 如果已定义,则表示数据流所有者为该数据流要求的保留时间。 |
| 68 | + |
| 69 | + - `effective_retention` |
| 70 | + |
| 71 | + (可选,字符串)如果定义,则添加到此数据流中的每个文档都将至少在此时间段内保存。在此期限之后的任何时间,文档都可能被删除。如果为空,该数据流中的每份文档都将无限期存储。为空时,该数据流中的每份文档都将无限期保存。有效保留时间的计算方法如[教程](/data_streams/data_stream_lifecycle/tutorial_data_stream_retention#如何计算有效保留时间?)所述。 |
| 72 | + |
| 73 | + - `retention_determined_by` |
| 74 | + |
| 75 | + (可选,字符串) 保留的来源,可以是三种值之一:`data_stream_configuration`、`default_retention` 或 `max_retention`。 |
| 76 | + |
| 77 | + - `rollover` |
| 78 | + |
| 79 | + (可选,对象)由集群设置 `cluster.lifecycle.default.rollover` 配置的触发后备索引翻转的条件。该属性是一个实现细节,只有当查询参数 `include_defaults` 设置为 `true` 时才能检索到。此字段的内容可能会更改。 |
| 80 | + |
| 81 | +- `global_retention` |
| 82 | + |
| 83 | + (对象)包含全局最大保留和默认保留。如果未配置全局保留,则该对象为空。 |
| 84 | + |
| 85 | + - `global_retention` 属性 |
| 86 | + |
| 87 | + - `max_retention` |
| 88 | + |
| 89 | + (可选,字符串) 数据流生命周期管理的数据流的有效保留时间不能超过此值。 |
| 90 | + |
| 91 | + - `default_retention` |
| 92 | + |
| 93 | + (可选,字符串) 这将是数据流生命周期管理的、未指定 `data_retention` 的数据流的有效保留时间。 |
| 94 | + |
| 95 | +## 示例 |
| 96 | + |
| 97 | +让我们检索生命周期: |
| 98 | + |
| 99 | +```bash |
| 100 | +GET _data_stream/my-data-stream*/_lifecycle |
| 101 | +``` |
| 102 | + |
| 103 | +响应如下: |
| 104 | + |
| 105 | +```json |
| 106 | +{ |
| 107 | + "data_streams": [ |
| 108 | + { |
| 109 | + "name": "my-data-stream-1", |
| 110 | + "lifecycle": { |
| 111 | + "enabled": true, |
| 112 | + "data_retention": "7d", |
| 113 | + "effective_retention": "7d", |
| 114 | + "retention_determined_by": "data_stream_configuration" |
| 115 | + } |
| 116 | + }, |
| 117 | + { |
| 118 | + "name": "my-data-stream-2", |
| 119 | + "lifecycle": { |
| 120 | + "enabled": true, |
| 121 | + "data_retention": "7d", |
| 122 | + "effective_retention": "7d", |
| 123 | + "retention_determined_by": "data_stream_configuration" |
| 124 | + } |
| 125 | + } |
| 126 | + ], |
| 127 | + "global_retention": {} |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +> [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams-get-lifecycle.html) |
0 commit comments