任务
/tasks
路由提供关于异步操作进度的信息。
任务对象
{
"uid": 4,
"batchUids": 0,
"indexUid": "movie",
"status": "failed",
"type": "indexDeletion",
"canceledBy": null,
"details": {
"deletedDocuments": 0
},
"error": {
"message": "Index `movie` not found.",
"code": "index_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found"
},
"duration": "PT0.001192S",
"enqueuedAt": "2022-08-04T12:28:15.159167Z",
"startedAt": "2022-08-04T12:28:15.161996Z",
"finishedAt": "2022-08-04T12:28:15.163188Z"
}
uid
类型: 整数
描述: 任务的唯一顺序标识符。
注意
任务 uid
在一个实例中的所有索引中递增。
batchUid
类型: 整数
描述: 此任务所属批次的唯一顺序标识符。
注意
批次 uid
在一个实例中的所有索引中递增。
indexUid
类型: 字符串
描述: 目标索引的唯一标识符
注意
对于全局任务,此值始终为 null
。
status
类型: 字符串
描述: 任务的状态。可能的值为 enqueued
、processing
、succeeded
、failed
和 canceled
type
类型: 字符串
描述: 任务执行的操作类型。可能的值为 indexCreation
、indexUpdate
、indexDeletion
、indexSwap
、documentAdditionOrUpdate
、documentDeletion
、settingsUpdate
、dumpCreation
、taskCancelation
、taskDeletion
和 snapshotCreation
canceledBy
类型: 整数
描述: 如果任务被取消,canceledBy
包含 taskCancelation
任务的 uid
。如果任务未被取消,canceledBy
始终为 null
details
类型: 对象
描述: 关于任务负载的详细信息。此对象的内容取决于任务的 type
documentAdditionOrUpdate
名称 | 描述 |
---|---|
receivedDocuments | 接收到的文档数量 |
indexedDocuments | 索引的文档数量。当任务状态为 enqueued 或 processing 时为 null |
documentDeletion
名称 | 描述 |
---|---|
providedIds | 排队等待删除的文档数量 |
originalFilter | 用于删除文档的过滤器。如果未指定,则为 null |
deletedDocuments | 已删除的文档数量。当任务状态为 enqueued 或 processing 时为 null |
indexCreation
名称 | 描述 |
---|---|
primaryKey | 索引创建期间提供的 primaryKey 字段的值。如果未指定,则为 null |
indexUpdate
名称 | 描述 |
---|---|
primaryKey | 索引更新期间提供的 primaryKey 字段的值。如果未指定,则为 null |
indexDeletion
名称 | 描述 |
---|---|
deletedDocuments | 已删除的文档数量。这应该等于已删除索引中的文档总数。当任务状态为 enqueued 或 processing 时为 null |
indexSwap
名称 | 描述 |
---|---|
swaps | 包含 indexSwap 任务负载的对象 |
settingsUpdate
名称 | 描述 |
---|---|
rankingRules | 排名规则列表 |
filterableAttributes | 可筛选属性列表 |
distinctAttribute | distinct 属性 |
searchableAttributes | 可搜索属性列表 |
displayedAttributes | 显示的属性列表 |
sortableAttributes | 可排序属性列表 |
stopWords | 停用词列表 |
synonyms | 同义词列表 |
typoTolerance | typoTolerance 对象 |
pagination | pagination 对象 |
faceting | faceting 对象 |
dumpCreation
名称 | 描述 |
---|---|
dumpUid | 生成的转储 uid 。这也是生成的转储文件的名称。当任务状态为 enqueued 、processing 、canceled 或 failed 时为 null |
taskCancelation
名称 | 描述 |
---|---|
matchedTasks | 匹配的任务数。如果用于请求的 API 密钥无权访问索引,则与该索引相关的任务将不包含在 matchedTasks 中 |
canceledTasks | 成功取消的任务数。如果任务取消失败,则此值为 0 。当任务状态为 enqueued 或 processing 时为 null |
originalFilter | 在取消任务请求中使用的过滤器 |
注意
任务取消可能成功,但 canceledTasks: 0
仍为 0
。当 matchedTasks
匹配已完成的任务(succeeded
、failed
或 canceled
)时,会发生这种情况。
taskDeletion
名称 | 描述 |
---|---|
matchedTasks | 匹配的任务数。如果用于请求的 API 密钥无权访问索引,则与该索引相关的任务将不包含在 matchedTasks 中 |
deletedTasks | 成功删除的任务数。如果任务删除失败,则此值为 0 。当任务状态为 enqueued 或 processing 时为 null |
originalFilter | 在删除任务请求中使用的过滤器 |
注意
任务删除可能成功,但 deletedTasks: 0
仍为 0
。当 matchedTasks
匹配 enqueued
或 processing
任务时,会发生这种情况。
snapshotCreation
对于 snapshotCreation
任务,details
对象设置为 null
。
error
类型: 对象
描述: 如果任务状态为 failed
,则此对象包含错误定义。否则,设置为 null
duration
类型: 字符串
描述: 任务在 processing
状态下花费的总时间,以 ISO 8601 格式表示
enqueuedAt
类型: 字符串
描述: 任务首次 enqueued
的日期和时间,以 RFC 3339 格式表示
startedAt
类型: 字符串
描述: 任务开始 processing
的日期和时间,以 RFC 3339 格式表示
finishedAt
类型: 字符串
描述: 任务完成 processing
的日期和时间,无论结果是 failed
、succeeded
还是 canceled
,都以 RFC 3339 格式表示
摘要任务对象
当 API 请求触发异步进程时,Meilisearch 返回一个摘要任务对象。此对象包含以下字段
您可以使用此 taskUid
获取关于任务状态的更多详细信息。
获取任务
全局列出所有任务,无论索引如何。task
对象包含在 results
数组中。
任务始终以 uid
的降序返回。这意味着默认情况下,最近创建的 task
对象首先出现。
查询参数
查询参数 | 默认值 | 描述 |
---|---|---|
uids | * (所有 uids) | 按任务的 uid 筛选任务。用逗号 (, ) 分隔多个任务 uids |
batchUids | * (所有批次 uids) | 按任务的 batchUid 筛选任务。用逗号 (, ) 分隔多个 batchUids |
statuses | * (所有状态) | 按任务的 status 筛选任务。用逗号 (, ) 分隔多个任务 statuses |
types | * (所有类型) | 按任务的 type 筛选任务。用逗号 (, ) 分隔多个任务 types |
indexUids | * (所有索引) | 按任务的 indexUid 筛选任务。用逗号 (, ) 分隔多个任务 indexUids 。区分大小写 |
limit | 20 | 要返回的任务数 |
from | 上次创建的任务的 uid | 返回的第一个任务的 uid |
reverse | false | 如果为 true ,则以相反的顺序返回结果,从最旧到最新 |
canceledBy | N/A | 按任务的 canceledBy 字段筛选任务。用逗号 (, ) 分隔多个任务 uids |
beforeEnqueuedAt | * (所有任务) | 按任务的 enqueuedAt 字段筛选任务 |
beforeStartedAt | * (所有任务) | 按任务的 startedAt 字段筛选任务 |
beforeFinishedAt | * (所有任务) | 按任务的 finishedAt 字段筛选任务 |
afterEnqueuedAt | * (所有任务) | 按任务的 enqueuedAt 字段筛选任务 |
afterStartedAt | * (所有任务) | 按任务的 startedAt 字段筛选任务 |
afterFinishedAt | * (所有任务) | 按任务的 finishedAt 字段筛选任务 |
响应
名称 | 类型 | 描述 |
---|---|---|
results | 数组 | 任务对象数组 |
total | 整数 | 与过滤器或查询匹配的任务总数 |
limit | 整数 | 返回的任务数 |
from | 整数 | 返回的第一个任务的 uid |
next | 整数 | 传递给 from 的值,用于查看下一“页”结果。当 next 的值为 null 时,表示没有更多任务可查看。 |
示例
curl \
-X GET 'MEILISEARCH_URL/tasks'
响应: 200 Ok
{
"results": [
{
"uid": 1,
"indexUid": "movies_reviews",
"status": "failed",
"type": "documentAdditionOrUpdate",
"canceledBy": null,
"details": {
"receivedDocuments": 100,
"indexedDocuments": 0
},
"error": null,
"duration": null,
"enqueuedAt": "2021-08-12T10:00:00.000000Z",
"startedAt": null,
"finishedAt": null
},
{
"uid": 0,
"indexUid": "movies",
"status": "succeeded",
"type": "documentAdditionOrUpdate",
"canceledBy": null,
"details": {
"receivedDocuments": 100,
"indexedDocuments": 100
},
"error": null,
"duration": "PT16S",
"enqueuedAt": "2021-08-11T09:25:53.000000Z",
"startedAt": "2021-08-11T10:03:00.000000Z",
"finishedAt": "2021-08-11T10:03:16.000000Z"
}
],
"total": 50,
"limit": 20,
"from": 1,
"next": null
}
获取单个任务
获取单个任务。
注意
如果您尝试检索已删除的任务,Meilisearch 将返回 task_not_found
错误。
路径参数
名称 | 类型 | 描述 |
---|---|---|
task_uid * | 字符串 | 请求任务的 uid |
示例
curl \
-X GET 'MEILISEARCH_URL/tasks/1'
响应: 200 Ok
{
"uid": 1,
"indexUid": "movies",
"status": "succeeded",
"type": "settingsUpdate",
"canceledBy": null,
"details": {
"rankingRules": [
"typo",
"ranking:desc",
"words",
"proximity",
"attribute",
"exactness"
]
},
"error": null,
"duration": "PT1S",
"enqueuedAt": "2021-08-10T14:29:17.000000Z",
"startedAt": "2021-08-10T14:29:18.000000Z",
"finishedAt": "2021-08-10T14:29:19.000000Z"
}
取消任务
根据任务的 uid
、status
、type
、indexUid
或任务入队 (enqueuedAt
) 或处理 (startedAt
) 的日期,取消任意数量的 enqueued
或 processing
任务。
任务取消是一项原子事务:要么所有任务都成功取消,要么全部不取消。
警告
为防止用户意外取消所有入队和处理中的任务,如果此路由在没有任何过滤器 (POST /tasks/cancel
) 的情况下使用,Meilisearch 将抛出 missing_task_filters
错误。
你知道吗?
您还可以取消 taskCancelation
类型的任务,只要它们处于 enqueued
或 processing
状态。这是可能的,因为 taskCancelation
类型的任务以相反的顺序处理,因此您最后入队的任务将首先被处理。
查询参数
需要有效的 uids
、statuses
、types
、indexUids
或日期 (beforeXAt
或 afterXAt
) 参数。
查询参数 | 描述 |
---|---|
uids | 根据 uid 取消任务。用逗号 (, ) 分隔多个 uids 。使用 uids=* 表示所有 uids |
statuses | 根据 status 取消任务。用逗号 (, ) 分隔多个 statuses 。使用 statuses=* 表示所有 statuses |
types | 根据 type 取消任务。用逗号 (, ) 分隔多个 types 。使用 types=* 表示所有 types |
indexUids | 根据 indexUid 取消任务。用逗号 (, ) 分隔多个 uids 。使用 indexUids=* 表示所有 indexUids 。区分大小写 |
beforeEnqueuedAt | 取消在指定的 enqueuedAt 日期之前的任务。使用 beforeEnqueuedAt=* 取消所有任务 |
beforeStartedAt | 取消在指定的 startedAt 日期之前的任务。使用 beforeStartedAt=* 取消所有任务 |
afterEnqueuedAt | 取消在指定的 enqueuedAt 日期之后的任务。使用 afterEnqueuedAt=* 取消所有任务 |
afterStartedAt | 取消在指定的 startedAt 日期之后的任务。使用 afterStartedAt=* 取消所有任务 |
注意
日期过滤器等同于 <
或 >
操作。目前,无法使用日期过滤器执行 ≤
或 ≥
操作。
示例
curl \
-X POST 'MEILISEARCH_URL/tasks/cancel?uids=1,2'
响应: 200 Ok
{
"taskUid": 3,
"indexUid": null,
"status": "enqueued",
"type": "taskCancelation",
"enqueuedAt": "2021-08-12T10:00:00.000000Z"
}
注意
由于 taskCancelation
是一个 全局任务,因此其 indexUid
始终为 null
。
您可以使用此 taskUid
获取有关 任务状态 的更多详细信息。
取消所有任务
您可以使用以下过滤器取消所有 processing
和 enqueued
任务
使用的 API 密钥必须有权访问所有索引 ("indexes": [*]
) 和 task.cancel
操作。
删除任务
根据 uid
、status
、type
、indexUid
、canceledBy
或日期删除已完成(succeeded
、failed
或 canceled
)的任务。任务删除是一项原子事务:要么所有任务都成功删除,要么全部不删除。
警告
为防止用户意外删除整个任务历史记录,如果此路由在没有任何过滤器 (DELETE /tasks
) 的情况下使用,Meilisearch 将抛出 missing_task_filters
错误。
查询参数
需要有效的 uids
、statuses
、types
、indexUids
、canceledBy
或日期 (beforeXAt
或 afterXAt
) 参数。
查询参数 | 描述 |
---|---|
uids | 根据 uid 删除任务。用逗号 (, ) 分隔多个 uids 。使用 uids=* 表示所有 uids |
statuses | 根据 status 删除任务。用逗号 (, ) 分隔多个 statuses 。使用 statuses=* 表示所有 statuses |
types | 根据 type 删除任务。用逗号 (, ) 分隔多个 types 。使用 types=* 表示所有 types |
indexUids | 根据 indexUid 删除任务。用逗号 (, ) 分隔多个 uids 。使用 indexUids=* 表示所有 indexUids 。区分大小写 |
canceledBy | 根据 canceledBy 字段删除任务 |
beforeEnqueuedAt | 删除在指定的 enqueuedAt 日期之前的任务。使用 beforeEnqueuedAt=* 删除所有任务 |
beforeStartedAt | 删除在指定的 startedAt 日期之前的任务。使用 beforeStartedAt=* 删除所有任务 |
beforeFinishedAt | 删除在指定的 finishedAt 日期之前的任务。使用 beforeFinishedAt=* 删除所有任务 |
afterEnqueuedAt | 删除在指定的 enqueuedAt 日期之后的任务。使用 afterEnqueuedAt=* 删除所有任务 |
afterStartedAt | 删除在指定的 startedAt 日期之后的任务。使用 afterStartedAt=* 删除所有任务 |
afterFinishedAt | 删除在指定的 finishedAt 日期之后的任务。使用 afterFinishedAt=* 删除所有任务 |
注意
日期过滤器等同于 <
或 >
操作。目前,无法使用日期过滤器执行 ≤
或 ≥
操作。
示例
curl \
-X DELETE 'MEILISEARCH_URL/tasks?uids=1,2'
响应: 200 Ok
{
"taskUid": 3,
"indexUid": null,
"status": "enqueued",
"type": "taskDeletion",
"enqueuedAt": "2021-08-12T10:00:00.000000Z"
}
注意
由于 taskDeletion
是一个 全局任务,因此其 indexUid
始终为 null
。
您可以使用此 taskUid
获取有关 任务状态 的更多详细信息。
删除所有任务
您可以使用以下过滤器删除所有已完成的任务
使用的 API 密钥必须有权访问所有索引 ("indexes": [*]
) 和 task.delete
操作。