【Elasticsearch】_reindex api请求

在Elasticsearch中,你可以使用 `_tasks` API 来检查 `_reindex` 任务的状态。当你发起一个 `_reindex` 请求时,Elasticsearch 会返回一个任务 ID,你可以使用这个任务 ID 来查询任务的详细状态。

以下是如何检查 `_reindex` 任务状态的步骤:

1. 获取任务 ID

首先,你需要获取 `_reindex` 任务的 ID。当你发送 `_reindex` 请求时,Elasticsearch 会返回一个响应,其中包含任务 ID。例如:

```json

POST _reindex

{

"source": {

"index": "kibana_sample_data_logs",

"size": 50

},

"dest": {

"index": "lang-test",

"pipeline": "my-lang-pipeline"

}

}

```

响应可能类似于:

```json

{

"took": 123,

"tasks": "node_id:task_id",

"total": 50,

"created": 50,

"deleted": 0,

"batches": 1,

"version_conflicts": 0,

"noops": 0,

"retries": {

"bulk": 0,

"search": 0

},

"throttled_millis": 0,

"requests_per_second": -1.0,

"throttled_until_millis": 0,

"failures": []

}

```

在这个响应中,`"tasks": "node_id:task_id"` 是任务的唯一标识符。

2. 使用 `_tasks` API 查询任务状态

你可以使用 `_tasks` API 来查询任务的详细状态。假设任务 ID 是 `node_id:task_id`,你可以发送以下请求来获取任务状态:

```json

GET _tasks/node_id:task_id

```

这将返回任务的详细信息,包括任务的状态、进度和任何潜在的错误信息。例如:

```json

{

"completed": true,

"task": {

"node": "node_id",

"id": 123456789,

"type": "transport",

"action": "indices:data/write/reindex",

"status": {

"total": 50,

"updated": 50,

"created": 50,

"deleted": 0,

"batches": 1,

"version_conflicts": 0,

"noops": 0,

"retries": {

"bulk": 0,

"search": 0

},

"throttled_millis": 0,

"requests_per_second": -1.0,

"throttled_until_millis": 0

},

"description": "reindex from [kibana_sample_data_logs] to [lang-test]",

"start_time_in_millis": 1642956000000,

"running_time_in_nanos": 123456789,

"cancellable": true,

"headers": {}

}

}

```

3. 检查任务状态

在返回的 JSON 中,你可以查看以下字段来了解任务的状态:

  • `completed`: 任务是否已完成。

  • `status`: 任务的详细状态,包括已处理的文档数量、创建的文档数量、删除的文档数量等。

  • `running_time_in_nanos`: 任务运行的时间(纳秒)。

  • `cancellable`: 任务是否可以取消。

通过这些信息,你可以了解 `_reindex` 任务的进展和结果。

4. 取消任务(可选)

如果需要取消正在进行的 `_reindex` 任务,你可以使用 `_tasks` API 的 `cancel` 功能。例如:

```json

POST _tasks/node_id:task_id/_cancel

```

这将尝试取消指定的任务。请注意,取消操作可能不会立即生效,具体取决于任务的当前状态和进度。

相关推荐
平凡君10 小时前
ElasticSearch查询指南:从青铜到王者的骚操作
大数据·elasticsearch·搜索引擎
songbaoxian10 小时前
ElasticSearch
java·linux·elasticsearch
易安杰14 小时前
ElasticSearch+Kibana通过Docker部署到Linux服务器中
linux·elasticsearch·搜索引擎·全文检索·中文分词
m0_7482475514 小时前
重学SpringBoot3-整合 Elasticsearch 8.x (二)使用Repository
大数据·elasticsearch·jenkins
liupan688916 小时前
文档检索服务平台
elasticsearch·全文检索·开源软件
m0_7482486517 小时前
SpringBoot整合easy-es
spring boot·后端·elasticsearch
m0_7482563418 小时前
重学SpringBoot3-整合 Elasticsearch 8.x (一)客户端方式
大数据·elasticsearch·jenkins
risc1234561 天前
【Elasticsearch】Search Templates(搜索模板)
elasticsearch
元气满满的热码式2 天前
logstash中的input插件(http插件,graphite插件)
网络·网络协议·http·elasticsearch·云原生
silianpan2 天前
文档检索服务平台
elasticsearch·搜索引擎·开源