【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

```

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

相关推荐
岳涛12 小时前
ES 9.2 起 ReadOnly 会设 indexing_complete,此前它要单独配
elasticsearch
喜欢吃燃面1 天前
Git 原理与使用(三):标签、多人协作与 Git Flow 落地
大数据·git·elasticsearch
喜欢吃燃面1 天前
Git 原理与使用(二):分支是平行宇宙,远程仓库是共享时空
大数据·git·elasticsearch
Elasticsearch1 天前
PHP 运行时指标:找出导致每个请求增加 24 毫秒耗时的 OPcache
elasticsearch
风翼靓崽2 天前
ES综合日志平台搭建
大数据·elasticsearch·搜索引擎
Java展博2 天前
[工程化基本功] 合并两条分支时,merge 和 rebase 到底改了谁的历史
大数据·elasticsearch·搜索引擎
Elasticsearch4 天前
借助 AWS Quick 和 Elastic Agent Builder 的 MCP 服务器,用自然语言查询百万笔交易
elasticsearch
Elasticsearch4 天前
你的第 95 百分位数掩盖了 95% 的请求,而 ES|QL 直方图能展示这些请求的分布
elasticsearch
崖边看雾4 天前
Git 手册:三区、分支、撤销、冲突与团队协作
大数据·git·elasticsearch
飞奔的瓜牛5 天前
Elasticsearch 日常巡检清单与实战避坑指南
大数据·elasticsearch·搜索引擎