data-streams-overview.asciidoc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. [role="xpack"]
  2. [[data-streams-overview]]
  3. == Data streams overview
  4. ++++
  5. <titleabbrev>Overview</titleabbrev>
  6. ++++
  7. A data stream consists of one or more _backing indices_. Backing indices are
  8. <<index-hidden,hidden>>, auto-generated indices used to store a stream's
  9. documents.
  10. image::images/data-streams/data-streams-diagram.svg[align="center"]
  11. The creation of a data stream requires a matching
  12. <<indices-templates,index template>>. This template acts as a blueprint for
  13. the stream's backing indices. It contains:
  14. * A name or wildcard (`*`) pattern for the data stream.
  15. * An optional mapping for the data stream's `@timestamp` field.
  16. +
  17. A `@timestamp` field must be included in every document indexed to the data
  18. stream. This field must be mapped as a <<date,`date`>> or
  19. <<date_nanos,`date_nanos`>> field data type. If no mapping is specified in the
  20. index template, the `date` field data type with default options is used.
  21. * The mappings and settings applied to each backing index when it's created.
  22. The same index template can be used to create multiple data streams.
  23. See <<set-up-a-data-stream>>.
  24. [discrete]
  25. [[data-streams-generation]]
  26. === Generation
  27. Each data stream tracks its _generation_: a six-digit, zero-padded integer
  28. that acts as a cumulative count of the data stream's backing indices. This count
  29. includes any deleted indices for the stream. The generation is incremented
  30. whenever a new backing index is added to the stream.
  31. When a backing index is created, the index is named using the following
  32. convention:
  33. [source,text]
  34. ----
  35. .ds-<data-stream>-<generation>
  36. ----
  37. .*Example*
  38. [%collapsible]
  39. ====
  40. The `web_server_logs` data stream has a generation of `34`. The most recently
  41. created backing index for this data stream is named
  42. `.ds-web_server_logs-000034`.
  43. ====
  44. Because the generation increments with each new backing index, backing indices
  45. with a higher generation contain more recent data. Backing indices with a lower
  46. generation contain older data.
  47. A backing index's name can change after its creation due to a
  48. <<indices-shrink-index,shrink>>, <<snapshots-restore-snapshot,restore>>, or
  49. other operations.
  50. [discrete]
  51. [[data-stream-write-index]]
  52. === Write index
  53. When a read request is sent to a data stream, it routes the request to all its
  54. backing indices. For example, a search request sent to a data stream would query
  55. all its backing indices.
  56. image::images/data-streams/data-streams-search-request.svg[align="center"]
  57. However, the most recently created backing index is the data stream’s only
  58. _write index_. The data stream routes all indexing requests for new documents to
  59. this index.
  60. image::images/data-streams/data-streams-index-request.svg[align="center"]
  61. You cannot add new documents to a stream's other backing indices, even by
  62. sending requests directly to the index. This means you cannot submit the
  63. following requests directly to any backing index except the write index:
  64. * An <<docs-index_,index API>> request with an
  65. <<docs-index-api-op_type,`op_type`>> of `create`. The `op_type` parameter
  66. defaults to `create` when adding new documents.
  67. * A <<docs-bulk,bulk API>> request using a `create` action
  68. Because it's the only index capable of ingesting new documents, you cannot
  69. perform operations on a write index that might hinder indexing. These
  70. prohibited operations include:
  71. * <<indices-clone-index,Clone>>
  72. * <<indices-close,Close>>
  73. * <<indices-delete-index,Delete>>
  74. * <<freeze-index-api,Freeze>>
  75. * <<indices-shrink-index,Shrink>>
  76. * <<indices-split-index,Split>>
  77. [discrete]
  78. [[data-streams-rollover]]
  79. === Rollover
  80. When a data stream is created, one backing index is automatically created.
  81. Because this single index is also the most recently created backing index, it
  82. acts as the stream's write index.
  83. A <<indices-rollover-index,rollover>> creates a new backing index for a data
  84. stream. This new backing index becomes the stream's write index, replacing
  85. the current one, and increments the stream's generation.
  86. In most cases, we recommend using <<index-lifecycle-management,{ilm}
  87. ({ilm-init})>> to automate rollovers for data streams. This lets you
  88. automatically roll over the current write index when it meets specified
  89. criteria, such as a maximum age or size.
  90. However, you can also use the <<indices-rollover-index,rollover API>> to
  91. manually perform a rollover. See <<manually-roll-over-a-data-stream>>.
  92. [discrete]
  93. [[data-streams-append-only]]
  94. === Append-only
  95. For most time-series use cases, existing data is rarely, if ever, updated.
  96. Because of this, data streams are designed to be append-only.
  97. You can send <<add-documents-to-a-data-stream,indexing requests for new
  98. documents>> directly to a data stream. However, you cannot send the following
  99. requests for existing documents directly to a data stream:
  100. * An <<docs-index_,index API>> request with an
  101. <<docs-index-api-op_type,`op_type`>> of `index`. The `op_type` parameter
  102. defaults to `index` for existing documents.
  103. * A <<docs-bulk,bulk API>> request using the `delete`, `index`, or `update`
  104. action.
  105. * A <<docs-delete,delete API>> request
  106. Instead, you can use the <<docs-update-by-query,update by query>> and
  107. <<docs-delete-by-query,delete by query>> APIs to update or delete existing
  108. documents in a data stream. See <<update-delete-docs-in-a-data-stream>>.
  109. Alternatively, you can update or delete a document by submitting requests to the
  110. backing index containing the document. See
  111. <<update-delete-docs-in-a-backing-index>>.
  112. TIP: If you frequently update or delete existing documents,
  113. we recommend using an <<indices-add-alias,index alias>> and
  114. <<indices-templates,index template>> instead of a data stream. You can still
  115. use <<index-lifecycle-management,{ilm-init}>> to manage indices for the alias.