Files
honeymoose f321dfedf5 同步完成!
**同步结果摘要**:

| 目录 | 同步前 | 同步后 | 官方 |
|------|--------|--------|------|
| aggregations | 40 | 65 | 64 |
| analyzers | 8 | 141 | 140 |
| api-reference | 97 | 186 | 174 |
| benchmark | 34 | 67 | 53 |
| clients | 17 | 18 | 18 |
| dashboards | 38 | 149 | 131 |
| data-prepper | 77 | 134 | 123 |
| im-plugin | 22 | 37 | 37 |
| ingest-pipelines | 27 | 52 | 51 |
| install-and-configure | 37 | 57 | 53 |
| ml-commons-plugin | 81 | 157 | 155 |
| observing-your-data | 39 | 73 | 66 |
| query-dsl | 40 | 77 | 75 |
| search-plugins | 80 | 139 | 95 |
| security-analytics | 22 | 47 | 46 |

**说明**:
- 本地文件数 > 官方:本地有一些官方已删除或重命名的文件
- 新增了约 **740 个英文文档文件**
- 已有文件保持不变(未覆盖)
2026-11-30 10:48:30 -05:00

243 lines
6.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
layout: default
title: Get data stream stats
parent: Data stream APIs
nav_order: 30
redirect_from:
- /api-reference/index-apis/data-stream-stats/
---
# Data Stream Stats API
**Introduced 1.0**
{: .label .label-purple }
The Data Stream Stats API provides statistics about one or more data streams, including the number of backing indexes, store size, and maximum timestamp. Use this API to monitor storage and indexing activity across data streams.
<!-- spec_insert_start
api: indices.data_streams_stats
component: endpoints
-->
## Endpoints
```json
GET /_data_stream/_stats
GET /_data_stream/{name}/_stats
```
<!-- spec_insert_end -->
<!-- spec_insert_start
api: indices.data_streams_stats
component: path_parameters
-->
## Path parameters
The following table lists the available path parameters. All path parameters are optional.
| Parameter | Data type | Description |
| :--- | :--- | :--- |
| `name` | List or String | A comma-separated list of data streams used to limit the request. Wildcard expressions (`*`) are supported. To target all data streams in a cluster, omit this parameter or use `*`. |
<!-- spec_insert_end -->
## Query parameters
The following table lists the available query parameters. All query parameters are optional.
| Parameter | Data type | Description | Default |
| :--- | :--- | :--- | :--- |
| `error_trace` | Boolean | Whether to include the stack trace of returned errors. | `false` |
| `filter_path` | List or String | Used to reduce the response. This parameter takes a comma-separated list of filters. It supports using wildcards to match any field or part of a field’s name. You can also exclude fields with `-`. | N/A |
| `human` | Boolean | Whether to return human-readable values for statistics. | `false` |
| `pretty` | Boolean | Whether to pretty format the returned JSON response. | `false` |
| `source` | String | The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. | N/A |
## Example requests
Create an index template with a matching pattern and data stream enabled:
<!-- spec_insert_start
component: example_code
rest: PUT /_index_template/template-logs-app
body: |
{
"index_patterns": ["logs-app*"],
"data_stream": {}
}
-->
{% capture step1_rest %}
PUT /_index_template/template-logs-app
{
"index_patterns": [
"logs-app*"
],
"data_stream": {}
}
{% endcapture %}
{% capture step1_python %}
response = client.indices.put_index_template(
name = "template-logs-app",
body = {
"index_patterns": [
"logs-app*"
],
"data_stream": {}
}
)
{% endcapture %}
{% include code-block.html
rest=step1_rest
python=step1_python %}
<!-- spec_insert_end -->
Create the data stream:
<!-- spec_insert_start
component: example_code
rest: PUT /_data_stream/logs-app
body: {}
-->
{% capture step1_rest %}
PUT /_data_stream/logs-app
{}
{% endcapture %}
{% capture step1_python %}
response = client.indices.create_data_stream(
name = "logs-app",
body = {}
)
{% endcapture %}
{% include code-block.html
rest=step1_rest
python=step1_python %}
<!-- spec_insert_end -->
Index a document to generate a backing index:
<!-- spec_insert_start
component: example_code
rest: POST /logs-app/_doc
body: |
{
"@timestamp": "2025-06-23T10:00:00Z",
"message": "app started"
}
-->
{% capture step1_rest %}
POST /logs-app/_doc
{
"@timestamp": "2025-06-23T10:00:00Z",
"message": "app started"
}
{% endcapture %}
{% capture step1_python %}
response = client.index(
index = "logs-app",
body = {
"@timestamp": "2025-06-23T10:00:00Z",
"message": "app started"
}
)
{% endcapture %}
{% include code-block.html
rest=step1_rest
python=step1_python %}
<!-- spec_insert_end -->
Retrieve statistics for the data stream:
<!-- spec_insert_start
component: example_code
rest: GET /_data_stream/logs-app/_stats?human=true
-->
{% capture step1_rest %}
GET /_data_stream/logs-app/_stats?human=true
{% endcapture %}
{% capture step1_python %}
response = client.indices.data_streams_stats(
name = "logs-app",
params = { "human": "true" }
)
{% endcapture %}
{% include code-block.html
rest=step1_rest
python=step1_python %}
<!-- spec_insert_end -->
## Example response
```json
{
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"data_stream_count": 1,
"backing_indices": 1,
"total_store_size": "16.8kb",
"total_store_size_bytes": 17304,
"data_streams": [
{
"data_stream": "logs-app",
"backing_indices": 1,
"store_size": "16.8kb",
"store_size_bytes": 17304,
"maximum_timestamp": 1750673100000
}
]
}
```
## Response body fields
| Field | Data type | Description |
| :--- | :--- | :--- |
| `_shards.total` | Integer | The total number of shards involved in the request. |
| `_shards.successful` | Integer | The number of successful shard fetches. |
| `_shards.failed` | Integer | The number of failed shard fetches. |
| `data_stream_count` | Integer | The total number of data streams returned in the response. |
| `backing_indices` | Integer | The total number of backing indexes across all data streams. |
| `total_store_size` | String | A human-readable total size of all data stream storage. Present only if `human=true`. |
| `total_store_size_bytes` | Integer | The total storage used by all data streams, in bytes. |
| `data_streams` | Array | A list of objects, one for each data stream. For object fields, see [The data stream objects](#the-data-stream-objects). |
### The data stream objects
Each data stream object contains the following fields.
| Field | Data type | Description |
| :--- | :--- | :--- |
| `data_stream` | String | The name of the data stream. |
| `backing_indices` | Integer | The number of backing indexes for the data stream. |
| `store_size` | String | Human-readable storage used by the data stream. Present only if `human=true`. |
| `store_size_bytes` | Integer | The total storage used by the data stream, in bytes. |
| `maximum_timestamp` | Long | The maximum timestamp across all documents in the data stream. |
## Required permissions
If you use the Security plugin, make sure you have the appropriate permissions: `indices:monitor/data_stream/stats`.
## Related documentation
- [Data streams]({{site.url}}{{site.baseurl}}/im-plugin/data-streams/)
- [Get data streams]({{site.url}}{{site.baseurl}}/api-reference/data-stream/data-stream-info/)