使用数据流
edit使用数据流
edit在您设置数据流之后,您可以执行以下操作:
将文档添加到数据流
edit要添加单个文档,请使用索引 API。Ingest pipelines 是受支持的。
POST /my-data-stream/_doc/ { "@timestamp": "2099-03-08T11:06:07.000Z", "user": { "id": "8a4f500d" }, "message": "Login successful" }
您不能使用索引 API 的 PUT /
请求格式向数据流添加新文档。要指定文档 ID,请改用 PUT /
格式。仅支持 op_type
为 create
。
要通过单个请求添加多个文档,请使用批量 API。
仅支持create
操作。
PUT /my-data-stream/_bulk?refresh {"create":{ }} { "@timestamp": "2099-03-08T11:04:05.000Z", "user": { "id": "vlb44hny" }, "message": "Login attempt failed" } {"create":{ }} { "@timestamp": "2099-03-08T11:06:07.000Z", "user": { "id": "8a4f500d" }, "message": "Login successful" } {"create":{ }} { "@timestamp": "2099-03-09T11:07:08.000Z", "user": { "id": "l7gk7f82" }, "message": "Logout successful" }
搜索数据流
edit以下搜索API支持数据流:
获取数据流的统计信息
edit使用数据流统计API来获取一个或多个数据流的统计信息:
GET /_data_stream/my-data-stream/_stats?human=true
手动滚动数据流
edit使用 rollover API 手动 滚动 一个数据流。您在手动滚动时有两种选择:
-
要立即触发滚动:
POST /my-data-stream/_rollover/
-
或者将滚动推迟到下一次索引事件发生时:
POST /my-data-stream/_rollover?lazy
使用第二个选项可以避免在数据流中出现空的备份索引,这些数据流不经常更新。
打开已关闭的支持索引
edit您无法搜索已关闭的备份索引,即使通过其数据流进行搜索也不行。您也无法更新或删除已关闭索引中的文档。
要重新打开已关闭的备份索引,请直接向索引提交一个打开索引API请求:
POST /.ds-my-data-stream-2099.03.07-000001/_open/
要重新打开数据流的所有已关闭的备份索引,请向数据流提交一个打开索引的API请求:
POST /my-data-stream/_open/
使用数据流重新索引
edit使用reindex API从现有索引、别名或数据流复制文档到数据流。因为数据流是仅追加的,所以重新索引到数据流必须使用op_type
为create
。重新索引无法更新数据流中的现有文档。
POST /_reindex { "source": { "index": "archive" }, "dest": { "index": "my-data-stream", "op_type": "create" } }
通过查询更新数据流中的文档
edit使用按查询更新API来更新数据流中匹配所提供查询的文档:
POST /my-data-stream/_update_by_query { "query": { "match": { "user.id": "l7gk7f82" } }, "script": { "source": "ctx._source.user.id = params.new_id", "params": { "new_id": "XgdX0NoX" } } }
通过查询删除数据流中的文档
edit使用delete by query API来删除数据流中匹配所提供查询的文档:
POST /my-data-stream/_delete_by_query { "query": { "match": { "user.id": "vlb44hny" } } }
更新或删除后备索引中的文档
edit如果需要,您可以通过向包含文档的支持索引发送请求来更新或删除数据流中的文档。您需要:
要获取此信息,请使用搜索请求:
GET /my-data-stream/_search { "seq_no_primary_term": true, "query": { "match": { "user.id": "yWIumJd7" } } }
响应:
{ "took": 20, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 1, "relation": "eq" }, "max_score": 0.2876821, "hits": [ { "_index": ".ds-my-data-stream-2099.03.08-000003", "_id": "bfspvnIBr7VVZlfp2lqX", "_seq_no": 0, "_primary_term": 1, "_score": 0.2876821, "_source": { "@timestamp": "2099-03-08T11:06:07.000Z", "user": { "id": "yWIumJd7" }, "message": "Login successful" } } ] } }
要更新文档,请使用带有有效if_seq_no
和if_primary_term
参数的索引API请求:
PUT /.ds-my-data-stream-2099-03-08-000003/_doc/bfspvnIBr7VVZlfp2lqX?if_seq_no=0&if_primary_term=1 { "@timestamp": "2099-03-08T11:06:07.000Z", "user": { "id": "8a4f500d" }, "message": "Login successful" }
要删除文档,请使用delete API:
DELETE /.ds-my-data-stream-2099.03.08-000003/_doc/bfspvnIBr7VVZlfp2lqX
要通过单个请求删除或更新多个文档,请使用批量 API的delete
、index
和update
操作。对于index
操作,请包含有效的if_seq_no
和if_primary_term
参数。
PUT /_bulk?refresh { "index": { "_index": ".ds-my-data-stream-2099.03.08-000003", "_id": "bfspvnIBr7VVZlfp2lqX", "if_seq_no": 0, "if_primary_term": 1 } } { "@timestamp": "2099-03-08T11:06:07.000Z", "user": { "id": "8a4f500d" }, "message": "Login successful" }