v0.25 版本的新功能
本月的發佈版本為 API 金鑰管理和非同步任務帶來重大變更。

在本文中,我們將探討 v0.25 版本引入的一些主要變更和重大變更。您也可以閱讀GitHub 上的完整更新日誌。
重大變更
API 金鑰管理
從這個版本開始,開發人員現在可以建立具有特定權限和到期日的 API 金鑰,以便精確控制哪些使用者/應用程式可以存取哪些索引和端點。
作為此功能的一部分,private
和 public
金鑰已被棄用,並由兩個具有類似權限的預設 API 金鑰取代:預設管理 API 金鑰
和 預設搜尋 API 金鑰
。
X-MEILI-API-KEY: <apiKey>
標頭已由 Authorization: Bearer <apiKey>
標頭取代。
假設您正在建立一個醫療產業的應用程式。以下是如何建立一個 API 金鑰,該金鑰僅有權限存取 patient_medical_records
索引上的搜尋端點
curl -X POST 'https://127.0.0.1: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 'https://127.0.0.1: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 'https://127.0.0.1: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" }
其他變更
- 跨版本相容性: 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 函式庫的協助。
如果您想瞭解更多我們在此處未提及的更新詳細資訊,請參閱我們的發佈變更日誌。