【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

```

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

相关推荐
Elastic 中国社区官方博客6 小时前
Elasticsearch 向量数据库:几分钟内完成部署,以经济高效的方式扩展至数千亿规模
大数据·运维·数据库·elasticsearch·搜索引擎·ai·全文检索
Elasticsearch9 小时前
将 Vercel 数据导入 Elastic:无需安装任何东西的无服务器可观测性
elasticsearch
Elastic 中国社区官方博客1 天前
Elasticsearch Python DSL 客户端开发
大数据·数据库·python·elasticsearch·搜索引擎·全文检索
阿里云大数据AI技术1 天前
Al Search x ES Agent Builder:让数据活起来,从搜索走向行动
人工智能·elasticsearch·agent
Elasticsearch1 天前
Elastic Agent Builder 中能够引用证据的 AI 根因分析
elasticsearch
考虑考虑1 天前
elasticSearch中的element_type
运维·后端·elasticsearch
CHANCE V1 天前
Elasticsearch 进阶
大数据·elasticsearch·搜索引擎
Elasticsearch1 天前
Elasticsearch 向量数据库:几分钟内完成部署,以经济高效的方式扩展至数千亿规模
elasticsearch
vx-Biye_Design2 天前
SSM伴侣动物伴护星小程序06330-计算机课程设计、毕业设计
spring boot·后端·elasticsearch·小程序·架构·课程设计·idea