Every document indexed into a data stream must contain a
@timestamp field. Elasticsearch uses this field internally to route documents to the correct backing index.When to use data streams
Data streams are the right choice when your data has these characteristics:Time-stamped
Each event has a
@timestamp field. Logs, metrics, traces, and security events all fit this pattern.Append-only
Documents are written once and not individually updated or deleted. New events always come in as new documents.
High volume
Data volumes are large enough that a single index becomes unwieldy. Data streams automatically roll over to new indices over time.
ILM-managed
You want Elasticsearch to manage index lifecycle (hot → warm → cold → delete) automatically using Index Lifecycle Management (ILM).
How data streams work
A data stream has one write index — the active backing index that receives new documents. When a rollover occurs (by schedule, size, or document count), Elasticsearch creates a new write index. Older backing indices remain available for search but stop accepting new documents. All backing indices follow the naming pattern.ds-{data-stream-name}-{timestamp}-{generation}.
Create an index template
Data streams require an index template that matches the stream name pattern and enables thedata_stream feature. The template defines the mapping and settings applied to each backing index.
Create the index template
The template must include
"data_stream": {} and an index_patterns list that matches the data stream name you plan to use:Index into a data stream
UsePOST /{data-stream-name}/_doc to add documents. You cannot use PUT with an explicit ID — data streams are append-only and do not support individual document replacement.
Use
create (not index) as the bulk action for data streams, since index with an ID is not allowed.Search across a data stream
A search against the data stream name queries across all backing indices transparently:Rollover
A rollover creates a new write index and promotes it to be the active backing index. The previous write index becomes read-only. Automatic rollover happens based on the conditions you configured in your ILM policy (max age, max size, max document count). Manual rollover lets you trigger a rollover immediately:Manage data streams
| Operation | Command |
|---|---|
| List all data streams | GET /_data_stream |
| Get a specific stream | GET /_data_stream/logs-app-prod |
| Get stats | GET /_data_stream/logs-app-prod/_stats |
| Delete a data stream | DELETE /_data_stream/logs-app-prod |
