data-streams-overview.asciidoc 5.4 KB

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