--- title: "Meilisearch" date: 2022-10-14T16:11:34+07:00 draft: false --- # meilisearch 快速文檔 ## 術語 - document 文檔是一個鍵值對對象,可以認為是 json 對象 - index (相同格式的)文檔組成 index,索引必須有主鍵(primary key),不包含主鍵的 document 不能插入 > 如果創建 index 時沒有設置 primary key,那麼會根據第一個插入的 document 來推導,規則是: 以不區分大小寫的方式找到以"id"結尾的字段 定義為主鍵(如 ID, uid, user_id), 不存在或存在多個都會引起失敗。 - settings: index 的設置 - displayedAttributes: 返回的 document 中包含的字段 - distinctAttributes: 返回的 document 中該字段值都不同 - faceting: - filterableAttributes: 用於過濾和切面的字段 - pagination: 分頁設置 - rankingRules: 按重要性排序的 ranking 規則列表 - searchableAttributes: 用於搜索的字段列表,按重要性排序 - sortableAttributes: 可排序字段列表 - stopWords: 用於搜索時忽略的詞表 - synonyms: 近似詞列表 - typoTolerance: 輸入容差設置 - task > 有可能影響搜索性能的操作置入 task queue,返回 taskUid 用於追蹤 task 狀態(enqueued, processing, succeeded, failed, canceled)[前兩個表示 task 未完成,其他表示已完成] > 不和 index 相關的 task 叫 Global tasks, 有 - dumpCreation - taskCancelation - taskDeletion - indexSwap - snapshotCreation > Global tasks 通過 `"indexes":[*]` 來訪問 > task 有優先級 - taskCancelation - taskDeletion - snapshotCreation - dumpCreation 優先處理,其他按入隊順序處理 - relevancy > 由搜索詞和搜索結果的相關性定義。由 settings 中的 rankingRules 作用。 > 內置的 6 個 rules 按順序配置(及含義)如下 ```json [ "words", // 匹配到的詞越多越靠前,所個搜索詞重要性從右至左 "type", // 輸入容差越少越靠前 "proximity", // 匹配到的詞越鄰近且順序一致越靠前 "attribute", // 根據 attribute 的優先級 "sort", // 受查詢 sort 參數影響 "exactness" // 匹配搜索詞越一致越靠前 ] ``` ## 配置/啟動參數 參見 https://www.meilisearch.com/docs/learn/configuration/instance_options#configuration-file-path ## 數據備份 - dumps 無模式,raw 數據,用於 meilisearch 版本升級 - snapshots 有模式,已索引,用於數據備份/回滾,但不兼容與各個版本 ## key與權限 啟動參數可使用 --master-key 指定一個 16 bytes的 utf8 字符串作為 master key。在 production 模式下,必須指定 master key 當以 master key 啟動後,除 `/health` 外的 API 都會受到保護, 必須包含 `Authorization` 頭才能成功執行 首次啟動後,會生成兩個 API key,一個可訪問 search 路由,一個可訪問 admin 路由 使用 master key 可通過 /key 路由管理 API key, 可創建任意 API key, 來管理各種資源 ## Language SDKs [多種語言API](https://www.meilisearch.com/docs/learn/what_is_meilisearch/sdks) ## Metrics 通過 `/metrics` 路由接入 prometheus. ## WebUI [meilisearch-ui](https://github.com/riccox/meilisearch-ui) > 多實例管理