v0.25 更新内容
本月发布版本对 API 密钥管理和异步任务进行了重大更改。

在本文中,我们将介绍 v0.25 引入的一些主要和破坏性更改。您还可以在 GitHub 上阅读完整的更改日志。
破坏性变更
API 密钥管理
从本发布版本开始,开发者现在可以创建具有特定权限和过期日期的 API 密钥,从而精确控制哪些用户/应用程序可以访问哪些索引和端点。
作为此功能的一部分,private
和 public
密钥已被弃用,并由两个具有类似权限的默认 API 密钥取代:Default Admin API Key
和 Default Search API Key
。
X-MEILI-API-KEY: <apiKey>
标头已被 Authorization: Bearer <apiKey>
标头取代。
假设您正在医疗行业中开发一个应用程序。以下是创建仅能访问 patient_medical_records
索引上搜索端点的 API 密钥的方法
curl -X POST 'http://localhost:7700/keys/' -H 'Content-Type: application/json' -H 'Authorization: Bearer [your_master_key]' --data-binary '{ "description": "Search patient records key", "actions": [ "search" ], "indexes": ["patient_medical_records"], "expiresAt": "2023-01-01T00:00:00Z" }'
响应:201 Created
{ "description": "Search patient records key", "key": "d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4", "actions": [ "search" ], "indexes": [ "patient_medical_records" ], "expiresAt": "2023-01-01T00:00:00Z", "createdAt": "2022-01-01T10:00:00Z", "updatedAt": "2022-01-01T10:00:00Z" }
用户随后可以使用此密钥对 patient_medical_records
索引发出搜索请求
curl -X POST 'http://localhost:7700/indexes/patient_medical_records/search' -H 'Content-Type: application/json' -H 'Authorization: Bearer d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4' --data-binary '{ "q": "trypophobia" }'
有关更多信息,请阅读我们关于 保护 Meilisearch 实例安全 的新指南。
异步操作
在 v0.25 中,我们彻底重塑了 Meilisearch 的异步操作,用新的 tasks
API 替换了 updates
API。
在相关的更改中,创建、更新和删除索引现在都是异步操作。此修复消除了竞态条件的可能性。
在 v0.25 之前,任何异步处理的请求(例如添加文档)都会返回一个 updateId
用于跟踪操作状态
{ "updateId": 1 }
在 v0.25 之后,异步操作现在将返回 任务 对象的摘要版本
{ "uid": 1, "indexUid": "patient_medical_records", "status": "enqueued", "type": "documentAddition", "enqueuedAt": "2021-08-10T14:29:17.000000Z", }
您可以使用 /tasks
路由获取完整的 任务 对象以及操作的当前状态。
curl -X GET 'http://localhost:7700/tasks/1'
响应:200 Ok
{ "uid": 1, "indexUid": "patient_medical_records", "status": "succeeded", "type": "documentAddition", "details": { "receivedDocuments": 1, "indexedDocuments": 1 }, "duration": "PT1S", "enqueuedAt": "2021-08-10T14:29:17.000000Z", "startedAt": "2021-08-10T14:29:18.000000Z", "finishedAt": "2021-08-10T14:29:19.000000Z" }
此处任务已成功。任务的其他可能状态包括 enqueued
、processing
或 failed
。
当任务失败时,Meilisearch 会在响应中返回一个 error
对象
{ "uid": 2, "indexUid": "patient_medical_records", "status": "failed", "type": "documentAddition", "details": { "receivedDocuments": 1, "indexedDocuments": 0 }, "error": { "message": "Document does not have a `:primaryKey` attribute: `:documentRepresentation`.", "code": "internal", "type": "missing_document_id", "link": "https://docs.meilisearch.com/errors#missing-document-id", }, "duration": "PT1S", "enqueuedAt": "2021-08-11T14:29:17.000000Z", "startedAt": "2021-08-11T14:29:18.000000Z", "finishedAt": "2021-08-11T14:29:19.000000Z" }
有关更多信息,请查阅 异步操作 文章或 任务 API 参考。
其他更改
- 跨版本兼容性: Meilisearch v0.25 及后续版本与 v0.22 之前创建的转储不兼容。
要将 v0.22 之前的转储迁移到 v0.25 Meilisearch,请首先将您的转储加载到 v0.24.0 中,使用 v0.24.0 创建一个转储,然后将此转储导入到 v0.25.0 中。 - 我们添加了一些新的错误消息,其中大多数与管理 API 密钥有关。
matches
现在高亮显示字符串和数值。- 我们添加了一些新的遥测指标。
贡献者
非常感谢所有贡献者!没有你们的帮助,这个项目无法走得太远。
感谢 @Mcdostone 和 @Thearas 对 Meilisearch 的帮助,以及 @datamaker 和 @Samyak2 对我们的 Tokenizer 库的帮助。
如果您想了解我们在此未提及的更多更新详情,请查阅我们的 发布更新日志。