| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 | [role="xpack"][[data-streams]]= Data streams++++<titleabbrev>Data streams</titleabbrev>++++A _data stream_ is a convenient, scalable way to ingest, search, and managecontinuously generated time series data.Time series data, such as logs, tends to grow over time. While storing an entiretime series in a single {es} index is simpler, it is often more efficient andcost-effective to store large volumes of data across multiple, time-basedindices. Multiple indices let you move indices containing older, less frequentlyqueried data to less expensive hardware and delete indices when they're nolonger needed, reducing overhead and storage costs.A data stream is designed to give you the best of both worlds:* The simplicity of a single named resource you can use for requests* The storage, scalability, and cost-saving benefits of multiple indicesYou can submit indexing and search requests directly to a data stream. Thestream automatically routes the requests to a collection of hidden_backing indices_ that store the stream's data.You can use <<index-lifecycle-management,{ilm} ({ilm-init})>> to automate themanagement of these backing indices. {ilm-init} lets you automatically spin upnew backing indices, allocate indices to different hardware, delete old indices,and take other automatic actions based on age or size criteria you set. Use datastreams and {ilm-init} to seamlessly scale your data storage based on yourbudget, performance, resiliency, and retention needs.[discrete][[when-to-use-data-streams]]== When to use data streamsWe recommend using data streams if you:* Use {es} to ingest, search, and manage large volumes of time series data* Want to scale and reduce costs by using {ilm-init} to automate the management  of your indices* Index large volumes of time series data in {es} but rarely delete or update  individual documents[discrete][[backing-indices]]== Backing indicesA data stream consists of one or more _backing indices_. Backing indices are<<index-hidden,hidden>>, auto-generated indices used to store a stream'sdocuments.image::images/data-streams/data-streams-diagram.svg[align="center"]To create backing indices, each data stream requires a matching<<indices-templates,index template>>. This template acts as a blueprint for thestream's backing indices. It specifies:* One or more wildcard (`*`) patterns that match the name of the stream.* The mappings and settings for the stream's backing indices.* That the template is used exclusively for data streams.Every document indexed to a data stream must have a `@timestamp` field. Thisfield can be mapped as a <<date,`date`>> or <<date_nanos,`date_nanos`>> fielddata type by the stream's index template. If the template does not specify amapping, the `@timestamp` field is mapped as a `date` field  with defaultoptions.The same index template can be used to create multiple data streams.[discrete][[data-streams-generation]]== GenerationEach data stream tracks its _generation_: a six-digit, zero-padded integerthat acts as a cumulative count of the data stream's backing indices. This countincludes any deleted indices for the stream. The generation is incrementedwhenever a new backing index is added to the stream.When a backing index is created, the index is named using the followingconvention:[source,text]----.ds-<data-stream>-<generation>----For example, the `web-server-logs` data stream has a generation of `34`. Themost recently created backing index for this data stream is named`.ds-web-server-logs-000034`.Because the generation increments with each new backing index, backing indiceswith a higher generation contain more recent data. Backing indices with a lowergeneration contain older data.A backing index's name can change after its creation due to a<<indices-shrink-index,shrink>>, <<snapshots-restore-snapshot,restore>>, orother operations. However, renaming a backing index does not detach it from adata stream.[discrete][[data-stream-read-requests]]== Read requestsWhen a read request is sent to a data stream, it routes the request to all itsbacking indices. For example, a search request sent to a data stream would queryall its backing indices.image::images/data-streams/data-streams-search-request.svg[align="center"][discrete][[data-stream-write-index]]== Write indexThe most recently created backing index is the data stream’s only_write index_. The data stream routes all indexing requests for new documents tothis index.image::images/data-streams/data-streams-index-request.svg[align="center"]You cannot add new documents to a stream's other backing indices, even bysending requests directly to the index.Because it's the only index capable of ingesting new documents, you cannotperform operations on a write index that might hinder indexing. Theseprohibited operations include:* <<indices-clone-index,Clone>>* <<indices-close,Close>>* <<indices-delete-index,Delete>>* <<freeze-index-api,Freeze>>* <<indices-shrink-index,Shrink>>* <<indices-split-index,Split>>[discrete][[data-streams-rollover]]== RolloverWhen a data stream is created, one backing index is automatically created.Because this single index is also the most recently created backing index, itacts as the stream's write index.A <<indices-rollover-index,rollover>> creates a new backing index for a datastream. This new backing index becomes the stream's write index, replacingthe current one, and increments the stream's generation.In most cases, we recommend using <<index-lifecycle-management,{ilm}({ilm-init})>> to automate rollovers for data streams. This lets youautomatically roll over the current write index when it meets specifiedcriteria, such as a maximum age or size.However, you can also use the <<indices-rollover-index,rollover API>> tomanually perform a rollover. See <<manually-roll-over-a-data-stream>>.[discrete][[data-streams-append-only]]== Append-onlyFor most time series use cases, existing data is rarely, if ever, updated.Because of this, data streams are designed to be append-only.You can send <<add-documents-to-a-data-stream,indexing requests for newdocuments>> directly to a data stream. However, you cannot send the update ordeletion requests for existing documents directly to a data stream.Instead, you can use the <<docs-update-by-query,update by query>> and<<docs-delete-by-query,delete by query>> APIs to update or delete existingdocuments in a data stream. See <<update-docs-in-a-data-stream-by-query>> and <<delete-docs-in-a-data-stream-by-query>>.If needed, you can update or delete a document by submitting requests to thebacking index containing the document. See<<update-delete-docs-in-a-backing-index>>.TIP: If you frequently update or delete existing documents,we recommend using an <<indices-add-alias,index alias>> and<<indices-templates,index template>> instead of a data stream. You can stilluse <<index-lifecycle-management,{ilm-init}>> to manage indices for the alias.include::set-up-a-data-stream.asciidoc[]include::use-a-data-stream.asciidoc[]include::change-mappings-and-settings.asciidoc[]
 |