在本文中,我们将深入了解 v0.25 引入的一些主要和重大更改。您还可以阅读GitHub 上的完整变更日志

重大更改

API 密钥管理

从本版本开始,开发人员现在可以创建具有特定权限和到期日期的 API 密钥,从而能够精确控制哪些用户/应用程序可以访问哪些索引和端点。

作为此功能的一部分,privatepublic 密钥已弃用,并由两个具有类似权限的默认 API 密钥代替:Default Admin API KeyDefault 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 已创建

{
    "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 确定

{
    "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"
}

这里任务已成功。任务的其他可能状态包括 enqueuedprocessingfailed

当任务失败时,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 库的帮助。


如果您想详细了解我们未在此处提及的更新,请查看我们的发布变更日志