2020-07-09 20:45:13 +08:00
|
|
|
|
[role="xpack"]
|
2020-06-11 01:40:54 +08:00
|
|
|
|
[[set-up-a-data-stream]]
|
|
|
|
|
== Set up a data stream
|
|
|
|
|
|
|
|
|
|
To set up a data stream, follow these steps:
|
|
|
|
|
|
|
|
|
|
. <<configure-a-data-stream-ilm-policy>>.
|
|
|
|
|
. <<create-a-data-stream-template>>.
|
|
|
|
|
. <<create-a-data-stream>>.
|
2020-07-08 23:54:55 +08:00
|
|
|
|
. <<secure-a-data-stream>>.
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
2020-12-09 02:28:35 +08:00
|
|
|
|
You can also <<convert-an-index-alias-to-a-data-stream,convert an existing index
|
|
|
|
|
alias to a data stream>>.
|
|
|
|
|
|
2020-06-11 01:40:54 +08:00
|
|
|
|
[discrete]
|
|
|
|
|
[[configure-a-data-stream-ilm-policy]]
|
2020-10-25 02:24:01 +08:00
|
|
|
|
=== Optional: Configure an {ilm-init} lifecycle policy
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
While optional, we recommend you configure an <<set-up-lifecycle-policy,{ilm}
|
|
|
|
|
({ilm-init}) policy>> to automate the management of your data stream's backing
|
|
|
|
|
indices.
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
In {kib}, open the menu and go to *Stack Management > Index Lifecycle Policies*.
|
2021-02-05 21:57:37 +08:00
|
|
|
|
Click *Create policy*.
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
2020-07-27 22:19:00 +08:00
|
|
|
|
[role="screenshot"]
|
2021-02-05 21:57:37 +08:00
|
|
|
|
image::images/ilm/create-policy.png[Create Policy page]
|
2020-07-27 22:19:00 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
[%collapsible]
|
|
|
|
|
.API example
|
|
|
|
|
====
|
|
|
|
|
Use the <<ilm-put-lifecycle,create lifecycle policy API>> to configure a policy:
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2020-08-06 20:37:44 +08:00
|
|
|
|
PUT /_ilm/policy/my-data-stream-policy
|
2020-06-11 01:40:54 +08:00
|
|
|
|
{
|
|
|
|
|
"policy": {
|
|
|
|
|
"phases": {
|
|
|
|
|
"hot": {
|
|
|
|
|
"actions": {
|
|
|
|
|
"rollover": {
|
2021-03-05 06:00:45 +08:00
|
|
|
|
"max_primary_shard_size": "25GB"
|
2020-06-11 01:40:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"delete": {
|
|
|
|
|
"min_age": "30d",
|
|
|
|
|
"actions": {
|
|
|
|
|
"delete": {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
----
|
2020-10-25 02:24:01 +08:00
|
|
|
|
====
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
|
|
|
|
[discrete]
|
|
|
|
|
[[create-a-data-stream-template]]
|
2020-10-25 02:24:01 +08:00
|
|
|
|
=== Create an index template
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
. In {kib}, open the menu and go to *Stack Management > Index Management*.
|
|
|
|
|
. In the *Index Templates* tab, click *Create template*.
|
|
|
|
|
. In the Create template wizard, use the *Data stream* toggle to indicate the
|
|
|
|
|
template is used for data streams.
|
|
|
|
|
. Use the wizard to finish defining your template. Specify:
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
2021-01-13 22:09:15 +08:00
|
|
|
|
* One or more index patterns that match the data stream's name. +
|
|
|
|
|
include::{es-repo-dir}/indices/create-data-stream.asciidoc[tag=data-stream-name]
|
2020-07-27 22:19:00 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
* Mappings and settings for the stream's backing indices.
|
2020-08-17 23:37:08 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
* A priority for the index template
|
|
|
|
|
+
|
2021-02-02 01:34:21 +08:00
|
|
|
|
include::{es-repo-dir}/indices/index-templates.asciidoc[tag=built-in-index-templates]
|
2020-08-17 23:37:08 +08:00
|
|
|
|
|
2021-02-02 21:36:37 +08:00
|
|
|
|
[[elastic-data-stream-naming-scheme]]
|
|
|
|
|
.The Elastic data stream naming scheme
|
|
|
|
|
****
|
|
|
|
|
The {agent} uses the Elastic data stream naming scheme to name its data streams.
|
|
|
|
|
To help you organize your data consistently and avoid naming collisions, we
|
|
|
|
|
recommend you also use the Elastic naming scheme for your other data streams.
|
|
|
|
|
|
|
|
|
|
The naming scheme splits data into different data streams based on the following
|
|
|
|
|
components. Each component corresponds to a
|
|
|
|
|
<<constant-keyword-field-type,constant keyword>> field defined in the
|
|
|
|
|
{ecs-ref}[Elastic Common Schema (ECS)].
|
|
|
|
|
|
|
|
|
|
`type`::
|
|
|
|
|
Generic type describing the data, such as `logs`, `metrics`, or `synthetics`.
|
|
|
|
|
Corresponds to the `data_stream.type` field.
|
|
|
|
|
|
|
|
|
|
`dataset`::
|
|
|
|
|
Describes the ingested data and its structure. Corresponds to the
|
|
|
|
|
`data_stream.dataset` field. Defaults to `generic`.
|
|
|
|
|
|
|
|
|
|
`namespace`::
|
|
|
|
|
User-configurable arbitrary grouping. Corresponds to the `data_stream.dataset`
|
|
|
|
|
field. Defaults to `default`.
|
|
|
|
|
|
|
|
|
|
The naming scheme separates these components with a `-` character:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
<type>-<dataset>-<namespace>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
For example, the {agent} uses the `logs-nginx.access-production` data
|
|
|
|
|
stream to store data with a type of `logs`, a dataset of `nginx.access`, and a
|
|
|
|
|
namespace of `production`. If you use the {agent} to ingest a log file, it
|
|
|
|
|
stores the data in the `logs-generic-default` data stream.
|
2021-02-03 22:36:02 +08:00
|
|
|
|
|
|
|
|
|
For more information about the naming scheme and its benefits, see our
|
|
|
|
|
https://www.elastic.co/blog/an-introduction-to-the-elastic-data-stream-naming-scheme[An
|
|
|
|
|
introduction to the Elastic data stream naming scheme] blog post.
|
2021-02-02 21:36:37 +08:00
|
|
|
|
****
|
|
|
|
|
|
2021-02-01 22:44:54 +08:00
|
|
|
|
include::{es-repo-dir}/data-streams/data-streams.asciidoc[tag=timestamp-reqs]
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
If using {ilm-init}, specify your lifecycle policy in the `index.lifecycle.name`
|
|
|
|
|
setting.
|
2021-02-01 22:44:54 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
TIP: Carefully consider your template's mappings and settings. Later changes may
|
|
|
|
|
require reindexing. See <<data-streams-change-mappings-and-settings>>.
|
2020-07-27 22:19:00 +08:00
|
|
|
|
|
|
|
|
|
[role="screenshot"]
|
|
|
|
|
image::images/data-streams/create-index-template.png[Create template page]
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
[%collapsible]
|
|
|
|
|
.API example
|
|
|
|
|
====
|
2021-03-16 02:49:44 +08:00
|
|
|
|
Use the <<indices-put-template,create or update index template API>> to create
|
|
|
|
|
an index template. The template must include a `data_stream` object, indicating
|
2020-10-25 02:24:01 +08:00
|
|
|
|
it's used for data streams.
|
2020-07-15 04:39:29 +08:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2020-08-06 20:37:44 +08:00
|
|
|
|
PUT /_index_template/my-data-stream-template
|
2020-07-15 04:39:29 +08:00
|
|
|
|
{
|
2020-08-06 20:37:44 +08:00
|
|
|
|
"index_patterns": [ "my-data-stream*" ],
|
2020-07-15 04:39:29 +08:00
|
|
|
|
"data_stream": { },
|
2021-02-16 23:53:28 +08:00
|
|
|
|
"priority": 500,
|
2020-07-15 04:39:29 +08:00
|
|
|
|
"template": {
|
|
|
|
|
"settings": {
|
2020-08-06 20:37:44 +08:00
|
|
|
|
"index.lifecycle.name": "my-data-stream-policy"
|
2020-07-15 04:39:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
// TEST[continued]
|
2020-10-25 02:24:01 +08:00
|
|
|
|
====
|
2020-06-23 20:45:11 +08:00
|
|
|
|
|
2020-06-11 01:40:54 +08:00
|
|
|
|
[discrete]
|
|
|
|
|
[[create-a-data-stream]]
|
2020-10-25 02:24:01 +08:00
|
|
|
|
=== Create the data stream
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
To automatically create the data stream, submit an
|
|
|
|
|
<<add-documents-to-a-data-stream,indexing request>> to the stream. The stream's
|
|
|
|
|
name must match one of your template's index patterns.
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2020-08-06 20:37:44 +08:00
|
|
|
|
POST /my-data-stream/_doc/
|
2020-06-11 01:40:54 +08:00
|
|
|
|
{
|
2020-12-15 06:46:54 +08:00
|
|
|
|
"@timestamp": "2099-03-07T11:04:05.000Z",
|
2020-06-11 01:40:54 +08:00
|
|
|
|
"user": {
|
|
|
|
|
"id": "vlb44hny"
|
|
|
|
|
},
|
|
|
|
|
"message": "Login attempt failed"
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
// TEST[continued]
|
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
You can also use the <<indices-create-data-stream,create data stream API>> to
|
|
|
|
|
manually create the data stream. The stream's name must match one of your
|
|
|
|
|
template's index patterns.
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2020-12-07 21:51:07 +08:00
|
|
|
|
PUT /_data_stream/my-data-stream
|
2020-06-11 01:40:54 +08:00
|
|
|
|
----
|
|
|
|
|
// TEST[continued]
|
2020-12-07 21:51:07 +08:00
|
|
|
|
// TEST[s/my-data-stream/my-data-stream-alt/]
|
2020-06-11 01:40:54 +08:00
|
|
|
|
|
2020-12-09 02:28:35 +08:00
|
|
|
|
When you create a data stream, {es} automatically creates a backing index for
|
|
|
|
|
the stream. This index also acts as the stream's first write index.
|
|
|
|
|
|
|
|
|
|
[discrete]
|
|
|
|
|
[[convert-an-index-alias-to-a-data-stream]]
|
|
|
|
|
=== Convert an index alias to a data stream
|
|
|
|
|
|
|
|
|
|
Prior to {es} 7.9, you would typically use an <<indices-aliases,index alias>>
|
|
|
|
|
with a write index to manage time series data. Data streams replace most of
|
|
|
|
|
this functionality and usually require less maintenance.
|
|
|
|
|
|
|
|
|
|
To convert an index alias with a write index to a new data stream with the same
|
|
|
|
|
name, use the <<indices-migrate-to-data-stream,migrate to data stream API>>.
|
|
|
|
|
During conversion, the alias’s indices become hidden backing indices for the
|
|
|
|
|
stream. The alias’s write index becomes the stream’s write index. Note the data
|
|
|
|
|
stream still requires a matching <<create-a-data-stream-template,index
|
|
|
|
|
template>>.
|
|
|
|
|
|
|
|
|
|
////
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
|
|
|
|
POST idx1/_doc/
|
|
|
|
|
{
|
|
|
|
|
"message" : "testing",
|
|
|
|
|
"@timestamp" : "2099-01-01"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
POST idx2/_doc/
|
|
|
|
|
{
|
|
|
|
|
"message" : "testing2",
|
|
|
|
|
"@timestamp" : "2099-01-01"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
POST /_aliases
|
|
|
|
|
{
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"add": {
|
|
|
|
|
"index": "idx1",
|
|
|
|
|
"alias": "my-time-series-data",
|
|
|
|
|
"is_write_index": true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"add": {
|
|
|
|
|
"index": "idx2",
|
|
|
|
|
"alias": "my-time-series-data"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PUT /_index_template/template
|
|
|
|
|
{
|
|
|
|
|
"index_patterns": ["my-time-series-data"],
|
|
|
|
|
"data_stream": { }
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
// TEST[continued]
|
|
|
|
|
////
|
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
|
|
|
|
POST /_data_stream/_migrate/my-time-series-data
|
|
|
|
|
----
|
|
|
|
|
// TEST[continued]
|
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
[discrete]
|
|
|
|
|
[[secure-a-data-stream]]
|
|
|
|
|
=== Secure the data stream
|
|
|
|
|
|
|
|
|
|
To control access to the data stream and its
|
|
|
|
|
data, use <<data-stream-privileges,{es}'s {security-features}>>.
|
|
|
|
|
|
2020-06-15 20:38:08 +08:00
|
|
|
|
[discrete]
|
|
|
|
|
[[get-info-about-a-data-stream]]
|
|
|
|
|
=== Get information about a data stream
|
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
In {kib}, open the menu and go to *Stack Management > Index Management*. In the
|
|
|
|
|
*Data Streams* tab, click the data stream's name.
|
2020-07-27 22:19:00 +08:00
|
|
|
|
|
|
|
|
|
[role="screenshot"]
|
|
|
|
|
image::images/data-streams/data-streams-list.png[Data Streams tab]
|
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
[%collapsible]
|
|
|
|
|
.API example
|
|
|
|
|
====
|
|
|
|
|
Use the <<indices-get-data-stream,get data stream API>> to retrieve information
|
|
|
|
|
about one or more data streams:
|
2020-07-08 23:02:30 +08:00
|
|
|
|
|
|
|
|
|
////
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2020-08-06 20:37:44 +08:00
|
|
|
|
POST /my-data-stream/_rollover/
|
2020-07-08 23:02:30 +08:00
|
|
|
|
----
|
|
|
|
|
// TEST[continued]
|
|
|
|
|
////
|
2020-06-15 20:38:08 +08:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2020-08-06 20:37:44 +08:00
|
|
|
|
GET /_data_stream/my-data-stream
|
2020-06-15 20:38:08 +08:00
|
|
|
|
----
|
2020-07-08 23:02:30 +08:00
|
|
|
|
// TEST[continued]
|
2020-10-25 02:24:01 +08:00
|
|
|
|
====
|
2020-07-08 23:54:55 +08:00
|
|
|
|
|
2020-06-15 20:38:08 +08:00
|
|
|
|
[discrete]
|
|
|
|
|
[[delete-a-data-stream]]
|
|
|
|
|
=== Delete a data stream
|
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
To delete a data stream and its backing indices, open the {kib} menu and go to
|
|
|
|
|
*Stack Management > Index Management*. In the *Data Streams* tab, click the
|
2021-01-07 23:45:26 +08:00
|
|
|
|
trash icon. The trash icon only displays if you have the `delete_index`
|
|
|
|
|
<<security-privileges, security privilege>> for the data stream.
|
2020-07-27 22:19:00 +08:00
|
|
|
|
|
|
|
|
|
[role="screenshot"]
|
2021-01-07 23:45:26 +08:00
|
|
|
|
image::images/data-streams/data-streams-no-delete.png[Data Streams tab]
|
2020-06-15 20:38:08 +08:00
|
|
|
|
|
2020-10-25 02:24:01 +08:00
|
|
|
|
[%collapsible]
|
|
|
|
|
.API example
|
|
|
|
|
====
|
|
|
|
|
Use the <<indices-delete-data-stream,delete data stream API>> to delete a data
|
|
|
|
|
stream and its backing indices:
|
2020-06-15 20:38:08 +08:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2020-08-06 20:37:44 +08:00
|
|
|
|
DELETE /_data_stream/my-data-stream
|
2020-06-15 20:38:08 +08:00
|
|
|
|
----
|
|
|
|
|
// TEST[continued]
|
2020-10-25 02:24:01 +08:00
|
|
|
|
====
|
2020-06-15 20:38:08 +08:00
|
|
|
|
|
|
|
|
|
////
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2020-07-08 23:02:30 +08:00
|
|
|
|
DELETE /_data_stream/*
|
|
|
|
|
DELETE /_index_template/*
|
2020-08-06 20:37:44 +08:00
|
|
|
|
DELETE /_ilm/policy/my-data-stream-policy
|
2020-06-15 20:38:08 +08:00
|
|
|
|
----
|
|
|
|
|
// TEST[continued]
|
|
|
|
|
////
|