data-streams.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. [chapter]
  2. [[data-streams]]
  3. = Data Streams
  4. You can use data streams to index time-based data that's continuously generated.
  5. A data stream groups indices from the same time-based data source.
  6. A data stream tracks its indices, known as _backing indices_, using an ordered
  7. list.
  8. A data stream's backing indices are <<index-hidden,hidden>>.
  9. While all backing indices handle read requests, the most recently created
  10. backing index is the data stream's only write index. A data stream only
  11. accepts <<docs-index_,index requests>> with `op_type` set to `create`. To update
  12. or delete specific documents in a data stream, submit a <<docs-delete,delete>>
  13. or <<docs-update,update>> API request to the backing index containing the
  14. document.
  15. To create a data stream, set up a <<indices-templates,composable index
  16. template>> containing:
  17. * A name or wildcard pattern for the data stream in the `index_patterns` property.
  18. * A `data_stream` definition that contains the `timestamp_field` property.
  19. The `timestamp_field` must be the primary timestamp field
  20. for the data source. This field must be included in every
  21. document indexed to the data stream.
  22. When you index one or more documents to a not-yet-existent target matching
  23. the template's name or pattern, {es} automatically creates the corresponding
  24. data stream. You can also manually create a data stream using the
  25. <<indices-create-data-stream,create data stream API>>. However, a composable
  26. template for the stream is still required.
  27. You can use the <<indices-rollover-index,rollover API>> to roll a data stream
  28. over to a new index when the current write index meets specified criteria, such
  29. as a maximum age or size. A rollover creates a new backing index and updates the
  30. data stream's list of backing indices. This new index then becomes the stream's
  31. new write index. See <<rollover-data-stream-ex>>.
  32. [discrete]
  33. [[create-data-stream]]
  34. == Create a data stream
  35. Create a composable template with a `data_stream` definition:
  36. [source,console]
  37. -----------------------------------
  38. PUT /_index_template/logs_template
  39. {
  40. "index_patterns": ["logs-*"],
  41. "data_stream": {
  42. "timestamp_field": "@timestamp"
  43. }
  44. }
  45. -----------------------------------
  46. Start indexing data to a target matching composable template's wildcard pattern:
  47. [source,console]
  48. ----
  49. POST /logs-foobar/_doc
  50. {
  51. "@timestamp": "2050-11-15T14:12:12",
  52. ...
  53. }
  54. ----
  55. // TEST[continued]
  56. // TEST[s/,//]
  57. // TEST[s/\.\.\.//]
  58. Response:
  59. [source,console-result]
  60. --------------------------------------------------
  61. {
  62. "_shards" : {
  63. "total" : 2,
  64. "failed" : 0,
  65. "successful" : 1
  66. },
  67. "_index" : "logs-foobar-000001",
  68. "_id" : "W0tpsmIBdwcYyG50zbta",
  69. "_version" : 1,
  70. "_seq_no" : 0,
  71. "_primary_term" : 1,
  72. "result": "created"
  73. }
  74. --------------------------------------------------
  75. // TESTRESPONSE[s/W0tpsmIBdwcYyG50zbta/$body._id/]
  76. Or create a data stream using the create data stream API:
  77. [source,console]
  78. --------------------------------------------------
  79. PUT /_data_stream/logs-barbaz
  80. --------------------------------------------------
  81. // TEST[continued]
  82. ////
  83. [source,console]
  84. -----------------------------------
  85. DELETE /_data_stream/logs-foobar
  86. DELETE /_data_stream/logs-barbaz
  87. DELETE /_index_template/logs_template
  88. -----------------------------------
  89. // TEST[continued]
  90. ////
  91. [discrete]
  92. [[data-streams-apis]]
  93. == Data stream APIs
  94. The following APIs are available for managing data streams:
  95. * To get information about data streams, use the <<indices-get-data-stream, get data stream API>>.
  96. * To delete data streams, use the <<indices-delete-data-stream, delete data stream API>>.
  97. * To manually create a data stream, use the <<indices-create-data-stream, create data stream API>>.