/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
类型:整数
描述:任务的唯一序列标识符。
batchUid
类型:整数
描述:此任务所属批次的唯一序列标识符。
indexUid
类型:字符串
描述:目标索引的唯一标识符
类型:字符串
描述:任务的状态。可能的值为 enqueued
(已排队)、processing
(处理中)、succeeded
(成功)、failed
(失败)和 canceled
(已取消)
类型:字符串
描述:任务执行的操作类型。可能的值为 indexCreation
(索引创建)、indexUpdate
(索引更新)、indexDeletion
(索引删除)、indexSwap
(索引交换)、documentAdditionOrUpdate
(文档添加或更新)、documentDeletion
(文档删除)、settingsUpdate
(设置更新)、dumpCreation
(转储创建)、taskCancelation
(任务取消)、taskDeletion
(任务删除)、databaseUpgrade
(数据库升级)、documentEdition
(文档编辑)和 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 | 唯一属性 |
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
。这发生在 matchedTasks
匹配已完成任务(succeeded
、failed
或 canceled
)时。
taskDeletion
名称 | 描述 |
---|
matchedTasks | 匹配任务的数量。如果用于请求的 API 密钥无权访问某个索引,则与该索引相关的任务将不会包含在 matchedTasks 中 |
deletedTasks | 成功删除的任务数量。如果任务删除失败,此值为 0 。当任务状态为 enqueued 或 processing 时为 null |
originalFilter | 删除任务请求中使用的过滤器 |
任务删除可能成功,但 deletedTasks: 0
。这发生在 matchedTasks
匹配 enqueued
或 processing
任务时。
snapshotCreation
对于 snapshotCreation
任务,details
对象设置为 null
。
error
类型:对象
描述:如果任务的状态为 failed
状态,则此对象包含错误定义。否则,设置为 null
名称 | 描述 |
---|
message | 错误的人类可读描述 |
code | 错误代码 |
类型 | 错误类型 |
链接 | 指向文档相关部分的链接 |
duration
类型:字符串
描述:任务在 processing
状态下花费的总时间,以 ISO 8601 格式表示
enqueuedAt
类型:字符串
描述:任务首次 enqueued
的日期和时间,以 RFC 3339 格式表示
startedAt
类型:字符串
描述:任务开始 processing
的日期和时间,以 RFC 3339 格式表示
finishedAt
类型:字符串
描述:任务完成 processing
的日期和时间,无论是 failed
、succeeded
还是 canceled
,以 RFC 3339 格式表示
简要任务对象
当 API 请求触发异步进程时,Meilisearch 返回一个简要任务对象。此对象包含以下字段
字段 | 类型 | 描述 |
---|
taskUid | 整数 | 唯一序列标识符 |
indexUid | 字符串 | 唯一索引标识符(对于全局任务始终为 null ) |
状态 | 字符串 | 任务的状态。值为 enqueued |
类型 | 字符串 | 任务类型 |
enqueuedAt | 字符串 | 表示任务已 enqueued 的日期和时间,采用 RFC 3339 格式 |
您可以使用此 taskUid
获取有关任务状态的更多详细信息。
获取任务
全局列出所有任务,无论索引如何。task
对象包含在 results
数组中。 任务始终按 uid
降序返回。这意味着默认情况下,最新创建的 task
对象首先出现。 任务结果是分页的,并且可以过滤。查询参数
查询参数 | 默认值 | 描述 |
---|
uids | * (所有 uids) | 按 uid 过滤任务。多个任务 uid 用逗号 (, ) 分隔 |
batchUids | * (所有批次 uids) | 按 batchUid 过滤任务。多个 batchUid 用逗号 (, ) 分隔 |
statuses | * (所有状态) | 按 status 过滤任务。多个任务 status 用逗号 (, ) 分隔 |
types | * (所有类型) | 按 type 过滤任务。多个任务 type 用逗号 (, ) 分隔 |
indexUids | * (所有索引) | 按 indexUid 过滤任务。多个任务 indexUid 用逗号 (, ) 分隔。区分大小写 |
limit | 20 | 要返回的任务数量 |
from | 最后创建任务的 uid | 返回的第一个任务的 uid |
reverse | false | 如果为 true ,则按相反顺序返回结果,从最旧到最新 |
canceledBy | 不适用 | 按 canceledBy 字段过滤任务。多个任务 uid 用逗号 (, ) 分隔 |
beforeEnqueuedAt | * (所有任务) | 按 enqueuedAt 字段过滤任务 |
beforeStartedAt | * (所有任务) | 按 startedAt 字段过滤任务 |
beforeFinishedAt | * (所有任务) | 按 finishedAt 字段过滤任务 |
afterEnqueuedAt | * (所有任务) | 按 enqueuedAt 字段过滤任务 |
afterStartedAt | * (所有任务) | 按 startedAt 字段过滤任务 |
afterFinishedAt | * (所有任务) | 按 finishedAt 字段过滤任务 |
名称 | 类型 | 描述 |
---|
results | 数组 | 任务对象数组 |
总数 | 整数 | 匹配过滤器或查询的任务总数 |
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
}
获取单个任务
获取单个任务。
路径参数
名称 | 类型 | 描述 |
---|
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"
}
取消任务
POST
/tasks/cancel?{query_parameter}
根据 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 取消任务。多个 uid 用逗号 (, ) 分隔。使用 uids=* 表示所有 uid |
statuses | 根据 status 取消任务。多个 status 用逗号 (, ) 分隔。使用 statuses=* 表示所有 status |
types | 根据 type 取消任务。多个 type 用逗号 (, ) 分隔。使用 types=* 表示所有 type |
indexUids | 根据 indexUid 取消任务。多个 uid 用逗号 (, ) 分隔。使用 indexUids=* 表示所有 indexUid 。区分大小写 |
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
任务
POST
/tasks/cancel?statuses=processing,enqueued
使用的 API 密钥必须有权访问所有索引("indexes": [*]
)和 task.cancel
操作。
删除任务
DELETE
/tasks?{query_parameter}
根据 uid
、status
、type
、indexUid
、canceledBy
或日期删除已完成(succeeded
、failed
或 canceled
)的任务。任务删除是原子事务:要么所有任务都成功删除,要么都没有。
查询参数
需要有效的 uids
、statuses
、types
、indexUids
、canceledBy
或日期(beforeXAt
或 afterXAt
)参数。
查询参数 | 描述 |
---|
uids | 根据 uid 删除任务。多个 uid 用逗号 (, ) 分隔。使用 uids=* 表示所有 uid |
statuses | 根据 status 删除任务。多个 status 用逗号 (, ) 分隔。使用 statuses=* 表示所有 status |
types | 根据 type 删除任务。多个 type 用逗号 (, ) 分隔。使用 types=* 表示所有 type |
indexUids | 根据 indexUid 删除任务。多个 uid 用逗号 (, ) 分隔。使用 indexUids=* 表示所有 indexUid 。区分大小写 |
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
获取有关任务状态的更多详细信息。
删除所有任务
您可以使用以下过滤器删除所有已完成的任务
DELETE
/tasks?statuses=failed,canceled,succeeded
使用的 API 密钥必须有权访问所有索引("indexes": [*]
)和 task.delete
操作。