2020-07-09 13:12:38 -04:00
|
|
|
[role="xpack"]
|
2020-06-10 14:03:46 -04:00
|
|
|
[[use-a-data-stream]]
|
|
|
|
== Use a data stream
|
|
|
|
|
2020-06-11 11:29:05 -04:00
|
|
|
After you <<set-up-a-data-stream,set up a data stream>>, you can do
|
2020-06-10 14:03:46 -04:00
|
|
|
the following:
|
|
|
|
|
|
|
|
* <<add-documents-to-a-data-stream>>
|
|
|
|
* <<search-a-data-stream>>
|
2020-07-20 09:50:26 -04:00
|
|
|
* <<get-stats-for-a-data-stream>>
|
2020-06-10 14:03:46 -04:00
|
|
|
* <<manually-roll-over-a-data-stream>>
|
2020-07-01 11:22:45 -04:00
|
|
|
* <<open-closed-backing-indices>>
|
2020-06-12 11:21:31 -04:00
|
|
|
* <<reindex-with-a-data-stream>>
|
2020-07-21 17:04:13 -04:00
|
|
|
* <<update-docs-in-a-data-stream-by-query>>
|
|
|
|
* <<delete-docs-in-a-data-stream-by-query>>
|
2020-06-30 08:35:13 -04:00
|
|
|
* <<update-delete-docs-in-a-backing-index>>
|
2020-06-10 14:03:46 -04:00
|
|
|
|
|
|
|
////
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
PUT /_index_template/my-data-stream-template
|
2020-06-10 14:03:46 -04:00
|
|
|
{
|
2020-08-06 09:38:35 -04:00
|
|
|
"index_patterns": [ "my-data-stream*" ],
|
2020-07-14 17:28:43 -04:00
|
|
|
"data_stream": { }
|
2020-06-10 14:03:46 -04:00
|
|
|
}
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
PUT /_data_stream/my-data-stream
|
2020-07-06 08:39:04 -04:00
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
POST /my-data-stream/_rollover/
|
2020-07-06 08:39:04 -04:00
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
POST /my-data-stream/_rollover/
|
2020-07-06 08:39:04 -04:00
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
PUT /my-data-stream/_create/bfspvnIBr7VVZlfp2lqX?refresh=wait_for
|
2020-07-06 08:39:04 -04:00
|
|
|
{
|
|
|
|
"@timestamp": "2020-12-07T11:06:07.000Z",
|
|
|
|
"user": {
|
|
|
|
"id": "yWIumJd7"
|
|
|
|
},
|
|
|
|
"message": "Login successful"
|
|
|
|
}
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
PUT /_data_stream/my-data-stream-alt
|
2020-06-10 14:03:46 -04:00
|
|
|
----
|
2020-07-06 08:39:04 -04:00
|
|
|
// TESTSETUP
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
|
|
|
DELETE /_data_stream/*
|
|
|
|
|
|
|
|
DELETE /_index_template/*
|
|
|
|
----
|
|
|
|
// TEARDOWN
|
2020-06-10 14:03:46 -04:00
|
|
|
////
|
|
|
|
|
|
|
|
[discrete]
|
|
|
|
[[add-documents-to-a-data-stream]]
|
|
|
|
=== Add documents to a data stream
|
|
|
|
|
2020-07-21 17:04:13 -04:00
|
|
|
You can add documents to a data stream using two types of indexing requests:
|
|
|
|
|
|
|
|
* <<data-streams-individual-indexing-requests>>
|
|
|
|
* <<data-streams-bulk-indexing-requests>>
|
|
|
|
|
|
|
|
Adding a document to a data stream adds the document to stream's current
|
|
|
|
<<data-stream-write-index,write index>>.
|
|
|
|
|
|
|
|
You cannot add new documents to a stream's other backing indices, even by
|
|
|
|
sending requests directly to the index. This means you cannot submit the
|
|
|
|
following requests directly to any backing index except the write index:
|
2020-06-10 14:03:46 -04:00
|
|
|
|
|
|
|
* An <<docs-index_,index API>> request with an
|
2020-07-21 17:04:13 -04:00
|
|
|
<<docs-index-api-op_type,`op_type`>> of `create`. The `op_type` parameter
|
|
|
|
defaults to `create` when adding new documents.
|
|
|
|
* A <<docs-bulk,bulk API>> request using a `create` action
|
|
|
|
|
|
|
|
|
|
|
|
[discrete]
|
|
|
|
[[data-streams-individual-indexing-requests]]
|
|
|
|
==== Individual indexing requests
|
|
|
|
|
|
|
|
You can use an <<docs-index_,index API>> request with an
|
|
|
|
<<docs-index-api-op_type,`op_type`>> of `create` to add individual documents
|
|
|
|
to a data stream.
|
|
|
|
|
2020-06-10 14:03:46 -04:00
|
|
|
NOTE: The `op_type` parameter defaults to `create` when adding new documents.
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The following index API request adds a new document to `my-data-stream`.
|
2020-06-10 14:03:46 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
POST /my-data-stream/_doc/
|
2020-06-10 14:03:46 -04:00
|
|
|
{
|
|
|
|
"@timestamp": "2020-12-07T11:06:07.000Z",
|
|
|
|
"user": {
|
|
|
|
"id": "8a4f500d"
|
|
|
|
},
|
|
|
|
"message": "Login successful"
|
|
|
|
}
|
|
|
|
----
|
2020-06-30 08:35:13 -04:00
|
|
|
|
|
|
|
IMPORTANT: You cannot add new documents to a data stream using the index API's
|
2020-06-30 09:52:03 -04:00
|
|
|
`PUT /<target>/_doc/<_id>` request format. To specify a document ID, use the
|
|
|
|
`PUT /<target>/_create/<_id>` format instead.
|
2020-06-10 14:03:46 -04:00
|
|
|
|
2020-07-21 17:04:13 -04:00
|
|
|
|
|
|
|
[discrete]
|
|
|
|
[[data-streams-bulk-indexing-requests]]
|
|
|
|
==== Bulk indexing requests
|
|
|
|
|
|
|
|
You can use the <<docs-bulk,bulk API>> to add multiple documents to a data
|
|
|
|
stream in a single request. Each action in the bulk request must use the
|
|
|
|
`create` action.
|
|
|
|
|
2020-06-10 14:03:46 -04:00
|
|
|
NOTE: Data streams do not support other bulk actions, such as `index`.
|
|
|
|
|
2020-06-17 17:06:28 -04:00
|
|
|
The following bulk API request adds several new documents to
|
2020-08-06 09:38:35 -04:00
|
|
|
`my-data-stream`. Only the `create` action is used.
|
2020-06-10 14:03:46 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
PUT /my-data-stream/_bulk?refresh
|
2020-07-06 08:39:04 -04:00
|
|
|
{"create":{ }}
|
2020-06-10 14:03:46 -04:00
|
|
|
{ "@timestamp": "2020-12-08T11:04:05.000Z", "user": { "id": "vlb44hny" }, "message": "Login attempt failed" }
|
2020-07-06 08:39:04 -04:00
|
|
|
{"create":{ }}
|
2020-06-10 14:03:46 -04:00
|
|
|
{ "@timestamp": "2020-12-08T11:06:07.000Z", "user": { "id": "8a4f500d" }, "message": "Login successful" }
|
2020-07-06 08:39:04 -04:00
|
|
|
{"create":{ }}
|
2020-06-10 14:03:46 -04:00
|
|
|
{ "@timestamp": "2020-12-09T11:07:08.000Z", "user": { "id": "l7gk7f82" }, "message": "Logout successful" }
|
|
|
|
----
|
|
|
|
|
2020-07-21 17:04:13 -04:00
|
|
|
[discrete]
|
|
|
|
[[data-streams-index-with-an-ingest-pipeline]]
|
|
|
|
==== Index with an ingest pipeline
|
|
|
|
|
|
|
|
You can use an <<ingest,ingest pipeline>> with an indexing request to
|
|
|
|
pre-process data before it's indexed to a data stream.
|
2020-07-13 09:03:36 -04:00
|
|
|
|
|
|
|
The following <<put-pipeline-api,put pipeline API>> request creates the
|
|
|
|
`lowercase_message_field` ingest pipeline. The pipeline uses the
|
|
|
|
<<lowercase-processor,`lowercase` ingest processor>> to change the `message`
|
|
|
|
field value to lowercase before indexing.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
|
|
|
PUT /_ingest/pipeline/lowercase_message_field
|
|
|
|
{
|
|
|
|
"description" : "Lowercases the message field value",
|
|
|
|
"processors" : [
|
|
|
|
{
|
|
|
|
"lowercase" : {
|
|
|
|
"field" : "message"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
----
|
|
|
|
// TEST[continued]
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The following index API request adds a new document to `my-data-stream`.
|
2020-07-13 09:03:36 -04:00
|
|
|
|
|
|
|
The request includes a `?pipeline=lowercase_message_field` query parameter.
|
|
|
|
This parameter indicates {es} should use the `lowercase_message_field` pipeline
|
|
|
|
to pre-process the document before indexing it.
|
|
|
|
|
|
|
|
During pre-processing, the pipeline changes the letter case of the document's
|
|
|
|
`message` field value from `LOGIN Successful` to `login successful`.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
POST /my-data-stream/_doc?pipeline=lowercase_message_field
|
2020-07-13 09:03:36 -04:00
|
|
|
{
|
|
|
|
"@timestamp": "2020-12-08T11:12:01.000Z",
|
|
|
|
"user": {
|
|
|
|
"id": "I1YBEOxJ"
|
|
|
|
},
|
|
|
|
"message": "LOGIN Successful"
|
|
|
|
}
|
|
|
|
----
|
|
|
|
// TEST[continued]
|
|
|
|
|
|
|
|
////
|
|
|
|
[source,console]
|
|
|
|
----
|
|
|
|
DELETE /_ingest/pipeline/lowercase_message_field
|
|
|
|
----
|
|
|
|
// TEST[continued]
|
|
|
|
////
|
2020-07-21 17:04:13 -04:00
|
|
|
|
2020-07-13 09:03:36 -04:00
|
|
|
|
2020-06-10 14:03:46 -04:00
|
|
|
[discrete]
|
|
|
|
[[search-a-data-stream]]
|
|
|
|
=== Search a data stream
|
|
|
|
|
|
|
|
The following search APIs support data streams:
|
|
|
|
|
|
|
|
* <<search-search, Search>>
|
|
|
|
* <<async-search, Async search>>
|
|
|
|
* <<search-multi-search, Multi search>>
|
|
|
|
* <<search-field-caps, Field capabilities>>
|
|
|
|
* <<eql-search-api, EQL search>>
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The following <<search-search,search API>> request searches `my-data-stream`
|
|
|
|
for documents with a timestamp between today and yesterday that also have
|
2020-06-10 14:03:46 -04:00
|
|
|
`message` value of `login successful`.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
GET /my-data-stream/_search
|
2020-06-10 14:03:46 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"bool": {
|
|
|
|
"must": {
|
|
|
|
"range": {
|
|
|
|
"@timestamp": {
|
|
|
|
"gte": "now-1d/d",
|
|
|
|
"lt": "now/d"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"should": {
|
|
|
|
"match": {
|
|
|
|
"message": "login successful"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2020-08-12 15:14:03 -04:00
|
|
|
You can use a comma-separated list to search
|
2020-06-18 08:59:00 -04:00
|
|
|
multiple data streams, indices, and index aliases in the same request.
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The following request searches `my-data-stream` and `my-data-stream-alt`,
|
|
|
|
which are specified as a comma-separated list in the request path.
|
2020-06-18 08:59:00 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
GET /my-data-stream,my-data-stream-alt/_search
|
2020-06-18 08:59:00 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match": {
|
|
|
|
"user.id": "8a4f500d"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
2020-08-12 15:14:03 -04:00
|
|
|
|
|
|
|
Index patterns are also supported.
|
|
|
|
|
|
|
|
The following request uses the `my-data-stream*` index pattern to search any
|
|
|
|
data stream, index, or index alias beginning with `my-data-stream`.
|
2020-06-18 08:59:00 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
GET /my-data-stream*/_search
|
2020-06-18 08:59:00 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match": {
|
|
|
|
"user.id": "vlb44hny"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
The following search request omits a target in the request path. The request
|
|
|
|
searches all data streams and indices in the cluster.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
|
|
|
GET /_search
|
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match": {
|
|
|
|
"user.id": "l7gk7f82"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2020-07-20 09:50:26 -04:00
|
|
|
[discrete]
|
|
|
|
[[get-stats-for-a-data-stream]]
|
|
|
|
=== Get statistics for a data stream
|
|
|
|
|
|
|
|
You can use the <<data-stream-stats-api,data stream stats API>> to retrieve
|
|
|
|
statistics for one or more data streams. These statistics include:
|
|
|
|
|
|
|
|
* A count of the stream's backing indices
|
|
|
|
* The total store size of all shards for the stream's backing indices
|
|
|
|
* The highest `@timestamp` value for the stream
|
|
|
|
|
|
|
|
.*Example*
|
|
|
|
[%collapsible]
|
|
|
|
====
|
2020-08-06 09:38:35 -04:00
|
|
|
The following data stream stats API request retrieves statistics for
|
|
|
|
`my-data-stream`.
|
2020-07-20 09:50:26 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
GET /_data_stream/my-data-stream/_stats?human=true
|
2020-07-20 09:50:26 -04:00
|
|
|
----
|
|
|
|
|
|
|
|
The API returns the following response.
|
|
|
|
|
|
|
|
[source,console-result]
|
|
|
|
----
|
|
|
|
{
|
|
|
|
"_shards": {
|
|
|
|
"total": 6,
|
|
|
|
"successful": 3,
|
|
|
|
"failed": 0
|
|
|
|
},
|
|
|
|
"data_stream_count": 1,
|
|
|
|
"backing_indices": 3,
|
|
|
|
"total_store_size": "624b",
|
|
|
|
"total_store_size_bytes": 624,
|
|
|
|
"data_streams": [
|
|
|
|
{
|
2020-08-06 09:38:35 -04:00
|
|
|
"data_stream": "my-data-stream",
|
2020-07-20 09:50:26 -04:00
|
|
|
"backing_indices": 3,
|
|
|
|
"store_size": "624b",
|
|
|
|
"store_size_bytes": 624,
|
|
|
|
"maximum_timestamp": 1607339167000
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
----
|
|
|
|
// TESTRESPONSE[s/"total_store_size": "624b"/"total_store_size": $body.total_store_size/]
|
|
|
|
// TESTRESPONSE[s/"total_store_size_bytes": 624/"total_store_size_bytes": $body.total_store_size_bytes/]
|
|
|
|
// TESTRESPONSE[s/"store_size": "624b"/"store_size": $body.data_streams.0.store_size/]
|
|
|
|
// TESTRESPONSE[s/"store_size_bytes": 624/"store_size_bytes": $body.data_streams.0.store_size_bytes/]
|
|
|
|
====
|
|
|
|
|
2020-06-10 14:03:46 -04:00
|
|
|
[discrete]
|
|
|
|
[[manually-roll-over-a-data-stream]]
|
|
|
|
=== Manually roll over a data stream
|
|
|
|
|
|
|
|
A rollover creates a new backing index for a data stream. This new backing index
|
2020-06-11 11:32:09 -04:00
|
|
|
becomes the stream's <<data-stream-write-index,write index>> and increments
|
|
|
|
the stream's <<data-streams-generation,generation>>.
|
2020-06-10 14:03:46 -04:00
|
|
|
|
|
|
|
In most cases, we recommend using <<index-lifecycle-management,{ilm-init}>> to
|
|
|
|
automate rollovers for data streams. This lets you automatically roll over the
|
|
|
|
current write index when it meets specified criteria, such as a maximum age or
|
|
|
|
size.
|
|
|
|
|
|
|
|
However, you can also use the <<indices-rollover-index,rollover API>> to
|
2020-06-16 16:20:32 -04:00
|
|
|
manually perform a rollover. This can be useful if you want to
|
|
|
|
<<data-streams-change-mappings-and-settings,apply mapping or setting changes>>
|
|
|
|
to the stream's write index after updating a data stream's template.
|
2020-06-10 14:03:46 -04:00
|
|
|
|
|
|
|
The following <<indices-rollover-index,rollover API>> request submits a manual
|
2020-08-06 09:38:35 -04:00
|
|
|
rollover request for `my-data-stream`.
|
2020-06-10 14:03:46 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
POST /my-data-stream/_rollover/
|
2020-06-10 14:03:46 -04:00
|
|
|
----
|
|
|
|
|
2020-07-01 11:22:45 -04:00
|
|
|
[discrete]
|
|
|
|
[[open-closed-backing-indices]]
|
|
|
|
=== Open closed backing indices
|
|
|
|
|
|
|
|
You may <<indices-close,close>> one or more of a data stream's backing indices
|
|
|
|
as part of its {ilm-init} lifecycle or another workflow. A closed backing index
|
|
|
|
cannot be searched, even for searches targeting its data stream. You also can't
|
2020-07-21 17:04:13 -04:00
|
|
|
<<update-docs-in-a-data-stream-by-query,update>> or
|
|
|
|
<<delete-docs-in-a-data-stream-by-query,delete>> documents in a closed index.
|
2020-07-01 11:22:45 -04:00
|
|
|
|
|
|
|
You can re-open individual backing indices by sending an
|
|
|
|
<<indices-open-close,open request>> directly to the index.
|
|
|
|
|
|
|
|
You also can conveniently re-open all closed backing indices for a data stream
|
|
|
|
by sending an open request directly to the stream.
|
|
|
|
|
2020-07-06 08:39:04 -04:00
|
|
|
The following <<cat-indices,cat indices>> API request retrieves the status for
|
2020-08-06 09:38:35 -04:00
|
|
|
`my-data-stream`'s backing indices.
|
2020-07-06 08:39:04 -04:00
|
|
|
|
2020-07-01 11:22:45 -04:00
|
|
|
////
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
POST /.ds-my-data-stream-000001,.ds-my-data-stream-000002/_close/
|
2020-07-01 11:22:45 -04:00
|
|
|
----
|
|
|
|
////
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
GET /_cat/indices/my-data-stream?v&s=index&h=index,status
|
2020-07-01 11:22:45 -04:00
|
|
|
----
|
|
|
|
// TEST[continued]
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The API returns the following response. The response indicates
|
|
|
|
`my-data-stream` contains two closed backing indices:
|
|
|
|
`.ds-my-data-stream-000001` and `.ds-my-data-stream-000002`.
|
2020-07-01 11:22:45 -04:00
|
|
|
|
|
|
|
[source,txt]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
index status
|
|
|
|
.ds-my-data-stream-000001 close
|
|
|
|
.ds-my-data-stream-000002 close
|
|
|
|
.ds-my-data-stream-000003 open
|
2020-07-01 11:22:45 -04:00
|
|
|
----
|
|
|
|
// TESTRESPONSE[non_json]
|
|
|
|
|
|
|
|
The following <<indices-open-close,open API>> request re-opens any closed
|
2020-08-06 09:38:35 -04:00
|
|
|
backing indices for `my-data-stream`, including
|
|
|
|
`.ds-my-data-stream-000001` and `.ds-my-data-stream-000002`.
|
2020-07-01 11:22:45 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
POST /my-data-stream/_open/
|
2020-07-01 11:22:45 -04:00
|
|
|
----
|
|
|
|
// TEST[continued]
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
You can resubmit the original cat indices API request to verify
|
|
|
|
`.ds-my-data-stream-000001` and `.ds-my-data-stream-000002` were re-opened.
|
2020-07-01 11:22:45 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
GET /_cat/indices/my-data-stream?v&s=index&h=index,status
|
2020-07-01 11:22:45 -04:00
|
|
|
----
|
|
|
|
// TEST[continued]
|
|
|
|
|
|
|
|
The API returns the following response.
|
|
|
|
|
|
|
|
[source,txt]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
index status
|
|
|
|
.ds-my-data-stream-000001 open
|
|
|
|
.ds-my-data-stream-000002 open
|
|
|
|
.ds-my-data-stream-000003 open
|
2020-07-01 11:22:45 -04:00
|
|
|
----
|
|
|
|
// TESTRESPONSE[non_json]
|
|
|
|
|
2020-06-12 11:21:31 -04:00
|
|
|
[discrete]
|
|
|
|
[[reindex-with-a-data-stream]]
|
|
|
|
=== Reindex with a data stream
|
|
|
|
|
|
|
|
You can use the <<docs-reindex,reindex API>> to copy documents to a data stream
|
|
|
|
from an existing index, index alias, or data stream.
|
|
|
|
|
|
|
|
A reindex copies documents from a _source_ to a _destination_. The source and
|
|
|
|
destination can be any pre-existing index, index alias, or data stream. However,
|
|
|
|
the source and destination must be different. You cannot reindex a data stream
|
|
|
|
into itself.
|
|
|
|
|
|
|
|
Because data streams are <<data-streams-append-only,append-only>>, a reindex
|
|
|
|
request to a data stream destination must have an `op_type` of `create`. This
|
|
|
|
means a reindex can only add new documents to a data stream. It cannot update
|
|
|
|
existing documents in the data stream destination.
|
|
|
|
|
|
|
|
A reindex can be used to:
|
|
|
|
|
|
|
|
* Convert an existing index alias and collection of time-based indices into a
|
|
|
|
data stream.
|
|
|
|
|
2020-06-26 11:52:58 -04:00
|
|
|
* Apply a new or updated <<create-a-data-stream-template,index template>>
|
2020-06-12 11:21:31 -04:00
|
|
|
by reindexing an existing data stream into a new one. This applies mapping
|
|
|
|
and setting changes in the template to each document and backing index of the
|
2020-06-16 16:20:32 -04:00
|
|
|
data stream destination. See
|
|
|
|
<<data-streams-use-reindex-to-change-mappings-settings>>.
|
2020-06-12 11:21:31 -04:00
|
|
|
|
|
|
|
TIP: If you only want to update the mappings or settings of a data stream's
|
|
|
|
write index, we recommend you update the <<create-a-data-stream-template,data
|
|
|
|
stream's template>> and perform a <<manually-roll-over-a-data-stream,rollover>>.
|
|
|
|
|
|
|
|
The following reindex request copies documents from the `archive` index alias to
|
2020-08-06 09:38:35 -04:00
|
|
|
`my-data-stream`. Because the destination is a data
|
|
|
|
stream, the request's `op_type` is `create`.
|
2020-06-12 11:21:31 -04:00
|
|
|
|
|
|
|
////
|
|
|
|
[source,console]
|
|
|
|
----
|
|
|
|
PUT /_bulk?refresh=wait_for
|
|
|
|
{"create":{"_index" : "archive_1"}}
|
|
|
|
{ "@timestamp": "2020-12-08T11:04:05.000Z" }
|
|
|
|
{"create":{"_index" : "archive_2"}}
|
|
|
|
{ "@timestamp": "2020-12-08T11:06:07.000Z" }
|
|
|
|
{"create":{"_index" : "archive_2"}}
|
|
|
|
{ "@timestamp": "2020-12-09T11:07:08.000Z" }
|
|
|
|
{"create":{"_index" : "archive_2"}}
|
|
|
|
{ "@timestamp": "2020-12-09T11:07:08.000Z" }
|
|
|
|
|
|
|
|
POST /_aliases
|
|
|
|
{
|
|
|
|
"actions" : [
|
|
|
|
{ "add" : { "index" : "archive_1", "alias" : "archive" } },
|
|
|
|
{ "add" : { "index" : "archive_2", "alias" : "archive", "is_write_index" : true} }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
----
|
|
|
|
////
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
|
|
|
POST /_reindex
|
|
|
|
{
|
|
|
|
"source": {
|
|
|
|
"index": "archive"
|
|
|
|
},
|
|
|
|
"dest": {
|
2020-08-06 09:38:35 -04:00
|
|
|
"index": "my-data-stream",
|
2020-06-12 11:21:31 -04:00
|
|
|
"op_type": "create"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
// TEST[continued]
|
|
|
|
|
|
|
|
You can also reindex documents from a data stream to an index, index
|
|
|
|
alias, or data stream.
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The following reindex request copies documents from `my-data-stream`
|
|
|
|
to the existing `archive` index alias. Because the destination is not a
|
|
|
|
data stream, the `op_type` does not need to be specified.
|
2020-06-12 11:21:31 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
|
|
|
POST /_reindex
|
|
|
|
{
|
|
|
|
"source": {
|
2020-08-06 09:38:35 -04:00
|
|
|
"index": "my-data-stream"
|
2020-06-12 11:21:31 -04:00
|
|
|
},
|
|
|
|
"dest": {
|
|
|
|
"index": "archive"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
// TEST[continued]
|
|
|
|
|
2020-06-17 12:41:24 -04:00
|
|
|
[discrete]
|
2020-07-21 17:04:13 -04:00
|
|
|
[[update-docs-in-a-data-stream-by-query]]
|
|
|
|
=== Update documents in a data stream by query
|
2020-06-17 12:41:24 -04:00
|
|
|
|
2020-07-21 17:04:13 -04:00
|
|
|
You cannot send indexing or update requests for existing documents directly to a
|
|
|
|
data stream. These prohibited requests include:
|
2020-06-30 08:35:13 -04:00
|
|
|
|
2020-07-21 17:04:13 -04:00
|
|
|
* An <<docs-index_,index API>> request with an
|
|
|
|
<<docs-index-api-op_type,`op_type`>> of `index`. The `op_type` parameter
|
|
|
|
defaults to `index` for existing documents.
|
|
|
|
|
|
|
|
* A <<docs-bulk,bulk API>> request using the `index` or `update`
|
|
|
|
action.
|
|
|
|
|
|
|
|
Instead, you can use the <<docs-update-by-query,update by query API>> to update
|
|
|
|
documents in a data stream that matches a provided query.
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The following update by query request updates documents in `my-data-stream`
|
|
|
|
with a `user.id` of `l7gk7f82`. The request uses a
|
2020-06-30 08:35:13 -04:00
|
|
|
<<modules-scripting-using,script>> to assign matching documents a new `user.id`
|
|
|
|
value of `XgdX0NoX`.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
POST /my-data-stream/_update_by_query
|
2020-06-30 08:35:13 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match": {
|
2020-07-06 08:39:04 -04:00
|
|
|
"user.id": "l7gk7f82"
|
2020-06-30 08:35:13 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"script": {
|
|
|
|
"source": "ctx._source.user.id = params.new_id",
|
|
|
|
"params": {
|
|
|
|
"new_id": "XgdX0NoX"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2020-07-21 17:04:13 -04:00
|
|
|
[discrete]
|
|
|
|
[[delete-docs-in-a-data-stream-by-query]]
|
|
|
|
=== Delete documents in a data stream by query
|
|
|
|
|
|
|
|
You cannot send document deletion requests directly to a data stream. These
|
|
|
|
prohibited requests include:
|
|
|
|
|
|
|
|
* A <<docs-delete,delete API>> request
|
|
|
|
|
|
|
|
* A <<docs-bulk,bulk API>> request using the `delete` action.
|
|
|
|
|
|
|
|
Instead, you can use the <<docs-delete-by-query,delete by query API>> to delete
|
|
|
|
documents in a data stream that matches a provided query.
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The following delete by query request deletes documents in `my-data-stream`
|
|
|
|
with a `user.id` of `vlb44hny`.
|
2020-06-30 08:35:13 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
POST /my-data-stream/_delete_by_query
|
2020-06-30 08:35:13 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match": {
|
2020-07-06 08:39:04 -04:00
|
|
|
"user.id": "vlb44hny"
|
2020-06-30 08:35:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
[discrete]
|
|
|
|
[[update-delete-docs-in-a-backing-index]]
|
|
|
|
=== Update or delete documents in a backing index
|
2020-06-17 12:41:24 -04:00
|
|
|
|
2020-06-30 08:35:13 -04:00
|
|
|
Alternatively, you can update or delete documents in a data stream by sending
|
|
|
|
the update or deletion request to the backing index containing the document. To
|
|
|
|
do this, you first need to get:
|
2020-06-17 12:41:24 -04:00
|
|
|
|
|
|
|
* The <<mapping-id-field,document ID>>
|
|
|
|
* The name of the backing index that contains the document
|
|
|
|
|
|
|
|
If you want to update a document, you must also get its current
|
|
|
|
<<optimistic-concurrency-control,sequence number and primary term>>.
|
|
|
|
|
|
|
|
You can use a <<search-a-data-stream,search request>> to retrieve this
|
|
|
|
information.
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The following search request retrieves documents in `my-data-stream`
|
|
|
|
with a `user.id` of `yWIumJd7`. By default, this search returns the
|
|
|
|
document ID and backing index for any matching documents.
|
2020-06-17 12:41:24 -04:00
|
|
|
|
|
|
|
The request includes a `"seq_no_primary_term": true` argument. This means the
|
|
|
|
search also returns the sequence number and primary term for any matching
|
|
|
|
documents.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
GET /my-data-stream/_search
|
2020-06-17 12:41:24 -04:00
|
|
|
{
|
|
|
|
"seq_no_primary_term": true,
|
|
|
|
"query": {
|
|
|
|
"match": {
|
|
|
|
"user.id": "yWIumJd7"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
The API returns the following response. The `hits.hits` property contains
|
|
|
|
information for any documents matching the search.
|
|
|
|
|
|
|
|
[source,console-result]
|
|
|
|
----
|
|
|
|
{
|
|
|
|
"took": 20,
|
|
|
|
"timed_out": false,
|
|
|
|
"_shards": {
|
2020-07-01 11:22:45 -04:00
|
|
|
"total": 3,
|
|
|
|
"successful": 3,
|
2020-06-17 12:41:24 -04:00
|
|
|
"skipped": 0,
|
|
|
|
"failed": 0
|
|
|
|
},
|
|
|
|
"hits": {
|
|
|
|
"total": {
|
|
|
|
"value": 1,
|
|
|
|
"relation": "eq"
|
|
|
|
},
|
|
|
|
"max_score": 0.2876821,
|
|
|
|
"hits": [
|
|
|
|
{
|
2020-08-06 09:38:35 -04:00
|
|
|
"_index": ".ds-my-data-stream-000003", <1>
|
2020-06-17 12:41:24 -04:00
|
|
|
"_type": "_doc",
|
|
|
|
"_id": "bfspvnIBr7VVZlfp2lqX", <2>
|
2020-07-06 08:39:04 -04:00
|
|
|
"_seq_no": 0, <3>
|
2020-06-17 12:41:24 -04:00
|
|
|
"_primary_term": 1, <4>
|
|
|
|
"_score": 0.2876821,
|
|
|
|
"_source": {
|
|
|
|
"@timestamp": "2020-12-07T11:06:07.000Z",
|
|
|
|
"user": {
|
|
|
|
"id": "yWIumJd7"
|
|
|
|
},
|
|
|
|
"message": "Login successful"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
// TESTRESPONSE[s/"took": 20/"took": $body.took/]
|
2020-06-30 08:35:13 -04:00
|
|
|
// TESTRESPONSE[s/"max_score": 0.2876821/"max_score": $body.hits.max_score/]
|
|
|
|
// TESTRESPONSE[s/"_score": 0.2876821/"_score": $body.hits.hits.0._score/]
|
2020-06-17 12:41:24 -04:00
|
|
|
|
|
|
|
<1> Backing index containing the matching document
|
|
|
|
<2> Document ID for the document
|
|
|
|
<3> Current sequence number for the document
|
|
|
|
<4> Primary term for the document
|
|
|
|
|
|
|
|
You can use an <<docs-index_,index API>> request to update an individual
|
|
|
|
document. To prevent an accidental overwrite, this request must include valid
|
|
|
|
`if_seq_no` and `if_primary_term` arguments.
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The following index API request updates an existing document in
|
|
|
|
`my-data-stream`. The request targets document ID
|
|
|
|
`bfspvnIBr7VVZlfp2lqX` in the `.ds-my-data-stream-000003` backing index.
|
2020-06-17 12:41:24 -04:00
|
|
|
|
|
|
|
The request also includes the current sequence number and primary term in the
|
|
|
|
respective `if_seq_no` and `if_primary_term` query parameters. The request body
|
|
|
|
contains a new JSON source for the document.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
PUT /.ds-my-data-stream-000003/_doc/bfspvnIBr7VVZlfp2lqX?if_seq_no=0&if_primary_term=1
|
2020-06-17 12:41:24 -04:00
|
|
|
{
|
|
|
|
"@timestamp": "2020-12-07T11:06:07.000Z",
|
|
|
|
"user": {
|
|
|
|
"id": "8a4f500d"
|
|
|
|
},
|
|
|
|
"message": "Login successful"
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
You use the <<docs-delete,delete API>> to delete individual documents. Deletion
|
|
|
|
requests do not require a sequence number or primary term.
|
|
|
|
|
2020-08-06 09:38:35 -04:00
|
|
|
The following index API request deletes an existing document in
|
|
|
|
`my-data-stream`. The request targets document ID
|
|
|
|
`bfspvnIBr7VVZlfp2lqX` in the `.ds-my-data-stream-000003` backing index.
|
2020-06-17 12:41:24 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
2020-08-06 09:38:35 -04:00
|
|
|
DELETE /.ds-my-data-stream-000003/_doc/bfspvnIBr7VVZlfp2lqX
|
2020-06-17 12:41:24 -04:00
|
|
|
----
|
|
|
|
|
|
|
|
You can use the <<docs-bulk,bulk API>> to delete or update multiple documents in
|
|
|
|
one request using `delete`, `index`, or `update` actions.
|
|
|
|
|
|
|
|
If the action type is `index`, the action must include valid
|
|
|
|
<<bulk-optimistic-concurrency-control,`if_seq_no` and `if_primary_term`>>
|
|
|
|
arguments.
|
|
|
|
|
|
|
|
The following bulk API request uses an `index` action to update an existing
|
2020-08-06 09:38:35 -04:00
|
|
|
document in `my-data-stream`.
|
2020-06-17 12:41:24 -04:00
|
|
|
|
|
|
|
The `index` action targets document ID `bfspvnIBr7VVZlfp2lqX` in the
|
2020-08-06 09:38:35 -04:00
|
|
|
`.ds-my-data-stream-000003` backing index. The action also includes the current
|
|
|
|
sequence number and primary term in the respective `if_seq_no` and
|
|
|
|
`if_primary_term` parameters.
|
2020-06-17 12:41:24 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
----
|
|
|
|
PUT /_bulk?refresh
|
2020-08-06 09:38:35 -04:00
|
|
|
{ "index": { "_index": ".ds-my-data-stream-000003", "_id": "bfspvnIBr7VVZlfp2lqX", "if_seq_no": 0, "if_primary_term": 1 } }
|
2020-06-17 12:41:24 -04:00
|
|
|
{ "@timestamp": "2020-12-07T11:06:07.000Z", "user": { "id": "8a4f500d" }, "message": "Login successful" }
|
|
|
|
----
|
|
|
|
|