設定

    使用 /settings 路由來為給定的索引自訂搜尋設定。您可以使用更新設定端點一次修改所有索引設定,或使用子路由來設定單一設定。

    如需索引設定的概念概述,請參閱索引說明。若要進一步了解索引設定的基本知識,請參閱索引設定教學課程

    設定介面

    Meilisearch Cloud 除了 /settings 路由外,還提供用於管理索引設定的使用者友善圖形介面。Cloud 介面提供更即時和可見的回饋,並且在與搜尋預覽結合使用時,有助於調整相關性。

    設定物件

    預設情況下,設定物件看起來像這樣。所有欄位皆可修改。

    {
      "displayedAttributes": [
        "*"
      ],
      "searchableAttributes": [
        "*"
      ],
      "filterableAttributes": [],
      "sortableAttributes": [],
      "rankingRules":
      [
        "words",
        "typo",
        "proximity",
        "attribute",
        "sort",
        "exactness"
      ],
      "stopWords": [],
      "nonSeparatorTokens": [],
      "separatorTokens": [],
      "dictionary": [],
      "synonyms": {},
      "distinctAttribute": null,
      "typoTolerance": {
        "enabled": true,
        "minWordSizeForTypos": {
          "oneTypo": 5,
          "twoTypos": 9
        },
        "disableOnWords": [],
        "disableOnAttributes": []
      },
      "faceting": {
        "maxValuesPerFacet": 100
      },
      "pagination": {
        "maxTotalHits": 1000
      },
      "proximityPrecision": "byWord",
      "facetSearch": true,
      "prefixSearch": "indexingTime",
      "searchCutoffMs": null
    }
    

    所有設定

    此路由允許您一次檢索、配置或重設索引的所有設定。

    取得設定

    GET/indexes/{index_uid}/settings

    取得索引的設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/movies/settings'
    回應:200 Ok
    {
      "displayedAttributes": [
        "*"
      ],
      "searchableAttributes": [
        "*"
      ],
      "filterableAttributes": [],
      "sortableAttributes": [],
      "rankingRules":
      [
        "words",
        "typo",
        "proximity",
        "attribute",
        "sort",
        "exactness"
      ],
      "stopWords": [],
      "nonSeparatorTokens": [],
      "separatorTokens": [],
      "dictionary": [],
      "synonyms": {},
      "distinctAttribute": null,
      "typoTolerance": {
        "enabled": true,
        "minWordSizeForTypos": {
          "oneTypo": 5,
          "twoTypos": 9
        },
        "disableOnWords": [],
        "disableOnAttributes": []
      },
      "faceting": {
        "maxValuesPerFacet": 100
      },
      "pagination": {
        "maxTotalHits": 1000
      },
      "proximityPrecision": "byWord",
      "facetSearch": true,
      "prefixSearch": "indexingTime",
      "searchCutoffMs": null
    }
    

    更新設定

    PATCH/indexes/{index_uid}/settings

    更新索引的設定。

    null 傳遞給索引設定會將其重設為預設值。

    設定路由中的更新是部分的。這表示任何未在主體中提供的參數將保持不變。

    如果提供的索引不存在,則會建立它。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    名稱類型預設值描述
    字典字串陣列Meilisearch 應解析為單個詞彙的字串列表
    displayedAttributes字串陣列所有屬性:["*"]在傳回的文件中顯示的欄位
    distinctAttribute字串null搜尋傳回具有給定欄位不同(不同)值的檔案
    faceting物件預設物件分面設定
    filterableAttributes字串陣列用作篩選器和分面的屬性
    pagination物件預設物件分頁設定
    proximityPrecision字串"byWord"計算鄰近排名規則時的精確度級別
    facetSearch布林值true啟用或停用 分面搜尋 功能
    prefixSearch字串"indexingTime"Meilisearch 何時應僅傳回符合查詢開頭的結果
    rankingRules字串陣列["words",
    "typo",
    "proximity",
    "attribute",
    "sort",
    "exactness"]
    依重要性排序的排名規則列表
    searchableAttributes字串陣列所有屬性:["*"]在其中搜尋符合查詢詞彙的欄位,依重要性順序排序
    searchCutoffMs整數null 或 1500 毫秒搜尋查詢的最大持續時間
    separatorTokens字串陣列分隔詞彙開始和結束位置的字元列表
    nonSeparatorTokens字串陣列不分隔詞彙開始和結束位置的字元列表
    sortableAttributes字串陣列在排序搜尋結果時使用的屬性
    stopWords字串陣列當出現在搜尋查詢中時,Meilisearch 會忽略的詞彙列表
    synonyms物件以類似方式處理的關聯詞彙列表
    typoTolerance物件預設物件錯字容忍設定
    embedders物件的物件預設物件執行基於含義的搜尋查詢所需的嵌入器

    範例

    curl \
      -X PATCH 'https://127.0.0.1:7700/indexes/movies/settings' \
      -H 'Content-Type: application/json' \
      --data-binary '{
        "rankingRules": [
          "words",
          "typo",
          "proximity",
          "attribute",
          "sort",
          "exactness",
          "release_date:desc",
          "rank:desc"
        ],
        "distinctAttribute": "movie_id",
        "searchableAttributes": [
          "title",
          "overview",
          "genres"
        ],
        "displayedAttributes": [
          "title",
          "overview",
          "genres",
          "release_date"
        ],
        "stopWords": [
          "the",
          "a",
          "an"
        ],
        "sortableAttributes": [
          "title",
          "release_date"
        ],
        "synonyms": {
          "wolverine": [
            "xmen",
            "logan"
        ],
          "logan": ["wolverine"]
        },
        "typoTolerance": {
          "minWordSizeForTypos": {
            "oneTypo": 8,
            "twoTypos": 10
          },
          "disableOnAttributes": ["title"]
        },
        "pagination": {
          "maxTotalHits": 5000
        },
        "faceting": {
          "maxValuesPerFacet": 200
        },
        "searchCutoffMs": 150
      }'
    警告

    如果 Meilisearch 在更新請求中的任何設定時遇到錯誤,它會立即停止處理請求並傳回錯誤訊息。在這種情況下,資料庫設定保持不變。傳回的錯誤訊息將僅處理遇到的第一個錯誤。

    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設設定

    DELETE/indexes/{index_uid}/settings

    將索引的所有設定重設為其 預設值

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/movies/settings'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    字典

    允許使用者透過新增使用者定義詞彙的補充字典來指示 Meilisearch 將字串群組視為單個詞彙。

    當處理包含許多特定領域詞彙的資料集,以及在日語等單字不以空格分隔的語言時,這特別有用。

    自訂字典在某些使用空格分隔的語言的用例中也很有用,例如具有 "J. R. R. Tolkien""W. E. B. Du Bois" 等名稱的資料集。

    提示

    使用者定義的字典可以與同義詞一起使用。配置 Meilisearch,以便作者姓名縮寫的不同拼寫傳回相同的結果會很有用

    "dictionary": ["W. E. B.", "W.E.B."],
    "synonyms": {
      "W. E. B.": ["W.E.B."],
      "W.E.B.": ["W. E. B."]
    }
    

    取得字典

    GET/indexes/{index_uid}/settings/dictionary

    取得索引的使用者定義字典。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/books/settings/dictionary'
    回應:200 OK
    []
    

    更新字典

    PUT/indexes/{index_uid}/settings/dictionary

    更新索引的使用者定義字典。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    ["J. R. R.", "W. E. B."]
    

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/books/settings/dictionary' \
      -H 'Content-Type: application/json' \
      --data-binary '[
        "J. R. R.",
        "W. E. B."
      ]'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2023-09-11T15:39:06.073314Z"
    }
    

    使用傳回的 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設字典

    DELETE/indexes/{index_uid}/settings/dictionary

    將索引的字典重設為其預設值,[]

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/books/settings/dictionary'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2022-04-14T20:53:32.863107Z"
    }
    

    使用傳回的 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    顯示屬性

    新增至 displayedAttributes 清單的屬性會出現在搜尋結果中。displayedAttributes 僅影響搜尋端點。它不會影響 使用 POST 取得文件使用 GET 取得文件 端點。

    依預設,displayedAttributes 陣列等於您資料集中的所有欄位。此行為以值 ["*"] 表示。

    若要深入了解顯示的屬性,請參閱我們的專用指南。

    取得顯示的屬性

    GET/indexes/{index_uid}/settings/displayed-attributes

    取得索引的顯示屬性。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/movies/settings/displayed-attributes'
    回應:200 Ok
    [
      "title",
      "overview",
      "genres",
      "release_date.year"
    ]
    

    更新顯示的屬性

    PUT/indexes/{index_uid}/settings/displayed-attributes

    更新索引的顯示屬性。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    [<String>, <String>, …]
    

    字串陣列。每個字串都應該是選定索引中存在的屬性。

    如果屬性包含物件,您可以使用點表示法來指定其一個或多個鍵,例如,"displayedAttributes": ["release_date.year"]

    警告

    如果欄位不存在,則不會擲回錯誤。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/movies/settings/displayed-attributes' \
      -H 'Content-Type: application/json' \
      --data-binary '[
        "title",
        "overview",
        "genres",
        "release_date"
      ]'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設顯示的屬性

    DELETE/indexes/{index_uid}/settings/displayed-attributes

    將索引的顯示屬性重設為預設值。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/movies/settings/displayed-attributes'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    相異屬性

    相異屬性是一個欄位,其值在傳回的文件中將永遠是唯一的。

    警告

    更新相異屬性將重新索引索引中的所有文件,這可能需要一些時間。我們建議您先更新索引設定,然後再新增文件,因為這可以減少 RAM 的消耗。

    若要深入了解相異屬性,請參閱我們的專用指南。

    取得相異屬性

    GET/indexes/{index_uid}/settings/distinct-attribute

    取得索引的相異屬性。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/shoes/settings/distinct-attribute'
    回應:200 Ok
    "skuid"
    

    更新相異屬性

    PUT/indexes/{index_uid}/settings/distinct-attribute

    更新索引的相異屬性欄位。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    <String>
    

    一個字串。該字串應該是選定索引中存在的屬性。

    如果屬性包含物件,您可以使用點表示法將其一個或多個鍵設定為此設定的值,例如,"distinctAttribute": "product.skuid"

    警告

    如果欄位不存在,則不會擲回錯誤。

    若要深入了解相異屬性,請參閱我們的專用指南。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/shoes/settings/distinct-attribute' \
      -H 'Content-Type: application/json' \
      --data-binary '"skuid"'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設相異屬性

    DELETE/indexes/{index_uid}/settings/distinct-attribute

    將索引的相異屬性重設為其預設值。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/shoes/settings/distinct-attribute'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    分面

    透過 Meilisearch,您可以建立 分面搜尋介面。此設定允許您

    若要深入了解分面,請參閱我們的專用指南。

    分面物件

    名稱類型預設值描述
    maxValuesPerFacet整數100每個分面傳回的最大分面值數量。值以升冪詞典順序排序
    sortFacetValuesBy物件所有分面值均以升冪字母數字順序排序 ("*": "alpha")自訂分面排序,以遞減的值計數 (count) 或遞增的字母數字順序 (alpha) 排序

    取得分面設定

    GET/indexes/{index_uid}/settings/faceting

    取得索引的分面設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/books/settings/faceting'
    回應:200 OK
    {
      "maxValuesPerFacet": 100,
      "sortFacetValuesBy": {
        "*": "alpha"
      }
    }
    

    更新分面設定

    PATCH/indexes/{index_uid}/settings/faceting

    部分更新索引的分面設定。任何未在 body 中提供的參數將保持不變。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    {
      "maxValuesPerFacet": <Integer>,
      "sortFacetValuesBy":{
          <String>: "count",
          <String>: "alpha"
      }
    }
    
    名稱類型預設值描述
    maxValuesPerFacet整數100每個分面傳回的最大分面值數量。值以升冪詞典順序排序
    sortFacetValuesBy物件所有分面值均以升冪字母數字順序排序 ("*": "alpha")自訂分面排序,以遞減的值計數 (count) 或遞增的字母數字順序 (alpha) 排序

    假設查詢的搜尋結果包含 colors 分面總共三個值:bluegreenred。如果您將 maxValuesPerFacet 設定為 2,Meilisearch 將僅在回應 body 的 facetDistribution 物件中傳回 bluegreen

    注意

    maxValuesPerFacet 設定為高值可能會對效能產生負面影響。

    範例

    以下程式碼範例將 maxValuesPerFacet 設定為 2,並將 genres 分面依遞減計數排序,以及所有其他分面依遞增的字母數字順序排序

    curl \
      -X PATCH 'https://127.0.0.1:7700/indexes/books/settings/faceting' \
      -H 'Content-Type: application/json' \
      --data-binary '{
        "maxValuesPerFacet": 2,
        "sortFacetValuesBy": {
          "*": "alpha",
          "genres": "count"
        }
      }'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2022-04-14T20:56:44.991039Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    重設分面設定

    將索引的分面設定重設為其預設值。將 sortFacetValuesBy 設定為 null(--data-binary '{ "sortFacetValuesBy": null }') 將會還原為預設值 ("*": "alpha")。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/books/settings/faceting'
    回應:200 OK
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2022-04-14T20:53:32.863107Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    可篩選的屬性

    filterableAttributes 清單中的屬性可用作篩選器或分面。

    警告

    更新可篩選的屬性將會重新索引索引中的所有文件,這可能需要一些時間。我們建議先更新您的索引設定,然後再新增文件,因為這可以減少 RAM 的消耗。

    若要進一步瞭解可篩選的屬性,請參閱我們的專用指南。

    取得可篩選的屬性

    GET/indexes/{index_uid}/settings/filterable-attributes

    取得索引的可篩選屬性。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/movies/settings/filterable-attributes'
    回應:200 Ok
    [
      "genres",
      "director",
      "release_date.year"
    ]
    

    更新可篩選的屬性

    PUT/indexes/{index_uid}/settings/filterable-attributes

    更新索引的可篩選屬性清單。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    [<String>, <String>, …]
    

    一個包含可在查詢時用作篩選器的屬性的字串陣列。

    如果屬性包含物件,您可以使用點表示法將其一個或多個鍵設定為此設定的值:"filterableAttributes": ["release_date.year"]

    警告

    如果欄位不存在,則不會擲回錯誤。

    若要進一步瞭解可篩選的屬性,請參閱我們的專用指南。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/movies/settings/filterable-attributes' \
      -H 'Content-Type: application/json' \
      --data-binary '[
        "genres",
        "director"
      ]'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設可篩選的屬性

    DELETE/indexes/{index_uid}/settings/filterable-attributes

    將索引的可篩選屬性清單重設回其預設值。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/movies/settings/filterable-attributes'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    本地化屬性

    預設情況下,Meilisearch 會自動偵測文件中使用的語言。此設定可讓您明確定義資料集中存在的語言,以及這些語言所在的欄位。

    本地化屬性會影響 searchableAttributesfilterableAttributessortableAttributes

    為單一索引設定多種語言可能會對效能產生負面影響。

    localeslocalizedAttributes

    localeslocalizedAttributes 的目標相同:在 Meilisearch 的語言自動偵測無法如預期運作時,明確指出搜尋中使用的語言。

    如果您認為 Meilisearch 因為查詢文字而偵測到不正確的語言,請使用 locales 明確設定搜尋語言。

    如果您認為 Meilisearch 因為文件而偵測到不正確的語言,請使用 localizedAttributes 在索引層級明確設定文件語言。

    為了完全掌控 Meilisearch 在索引和搜尋期間偵測語言的方式,請同時設定 localeslocalizedAttributes

    本地化屬性物件

    localizedAttributes 必須是區域設定物件的陣列。其預設值為 []

    區域設定物件必須具有以下欄位

    名稱類型預設值描述
    locales字串陣列[]一個字串清單,指示一個或多個 ISO-639 區域設定
    attribute_patterns字串陣列[]一個字串清單,指示哪些欄位對應到指定的區域設定

    locales

    Meilisearch 支援以下 ISO-639-3 三個字母的 localesepoengruscmnspaporitabenfradeuukrkatarahinjpnhebyidpolamhjavkornobdanswefinturnldhuncesellbulbelmarkanronslvhrvsrpmkdlitlavesttamvieurdthagujuzbpanazeindtelpesmalorimyanepsinkhmtukakazulsnaafrlatslkcattglhye

    您也可以使用支援的 localesISO-639-1 兩個字母的等效項目

    您也可以將空陣列指定給 locales。在這種情況下,Meilisearch 將自動偵測相關 attributePatterns 的語言。

    attributePatterns

    屬性模式可以 * 星號萬用字元開頭或結尾,以比對多個欄位:en_**-ar

    您也可以將 attributePatterns 設定為 *,在這種情況下,Meilisearch 會將所有欄位視為它們都採用相關的區域設定。

    取得本地化屬性設定

    GET/indexes/{index_uid}/settings/localized-attributes

    取得索引的本地化屬性設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/INDEX_NAME/settings/localized-attributes'
    回應:200 OK
    {
      "localizedAttributes": [
        {"locales": ["jpn"], "attributePatterns": ["*_ja"]}
      ]
    }
    

    更新本地化屬性設定

    PUT/indexes/{index_uid}/settings/localized-attributes

    更新索引的本地化屬性設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    {
      "localizedAttributes": [
        {
         "locale": [<String>, …],
         "attributePatterns": [<String>, …],
        }
      ]
    }
    
    名稱類型預設值描述
    localizedAttributes物件陣列[]為一個或多個屬性明確設定特定的區域設定

    範例

    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "INDEX_NAME",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2022-04-14T20:56:44.991039Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    重設分頁設定

    RESET/indexes/{index_uid}/settings/localized-attributes

    將索引的本地化屬性重設為其預設值

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "INDEX_NAME",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2022-04-14T20:53:32.863107Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    分頁

    為了保護您的資料庫免受惡意抓取,Meilisearch 每個搜尋預設限制為 1000 個結果。此設定可讓您設定每次搜尋傳回的最大結果數。

    maxTotalHits 的優先順序高於搜尋參數,例如 limitoffsethitsPerPagepage

    例如,如果您將 maxTotalHits 設定為 100,無論為 offset 設定的值為何,您都將無法存取超過 100 的搜尋結果。

    若要進一步瞭解如何使用 Meilisearch 將搜尋結果分頁,請參閱我們的專用指南。

    分頁物件

    名稱類型預設值描述
    maxTotalHits整數1000Meilisearch 可以傳回的最大搜尋結果數

    取得分頁設定

    GET/indexes/{index_uid}/settings/pagination

    取得索引的分頁設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/books/settings/pagination'
    回應:200 OK
    {
      "maxTotalHits": 1000
    }
    

    更新分頁設定

    PATCH/indexes/{index_uid}/settings/pagination

    部分更新索引的分頁設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    {maxTotalHits: <Integer>}
    
    名稱類型預設值描述
    maxTotalHits整數1000Meilisearch 可以傳回的最大搜尋結果數
    警告

    maxTotalHits 設定為高於預設值的值將會對搜尋效能產生負面影響。將 maxTotalHits 設定為超過 20000 的值可能會導致查詢需要數秒才能完成。

    範例

    curl \
      -X PATCH 'https://127.0.0.1:7700/indexes/books/settings/pagination' \
      -H 'Content-Type: application/json' \
      --data-binary '{
        "maxTotalHits": 100
      }'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2022-04-14T20:56:44.991039Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    重設分頁設定

    將索引的分頁設定重設為其預設值

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/books/settings/pagination'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2022-04-14T20:53:32.863107Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    鄰近度精確度

    計算單字之間的距離是一項資源密集型操作。降低此操作的精確度可能會顯著提高效能,並且在大多數使用案例中對結果的相關性影響不大。Meilisearch 在根據鄰近度對結果進行排序以及使用者執行片語搜尋時會使用單字距離。

    proximityPrecision 接受下列字串值之一

    取得鄰近度精確度設定

    GET/indexes/{index_uid}/settings/proximity-precision

    取得索引的鄰近度精確度設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/books/settings/proximity-precision'
    回應:200 OK
    "byWord"
    

    更新鄰近度精確度設定

    PUT/indexes/{index_uid}/settings/proximity-precision

    更新索引的分頁設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    "byWord"|"byAttribute"
    

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/books/settings/proximity-precision' \
      -H 'Content-Type: application/json' \
      --data-binary '"byAttribute"'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2023-04-14T15:50:29.821044Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    重設鄰近度精確度設定

    DELETE/indexes/{index_uid}/settings/proximity-precision

    將索引的鄰近度精確度設定重設為預設值。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/books/settings/proximity-precision'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2023-04-14T15:51:47.821044Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    處理用於切面搜尋的可篩選屬性是一項資源密集型操作。預設會啟用此功能,但停用它可以加快索引速度。

    facetSearch 接受單一布林值。如果設定為 false,則會停用整個索引的切面搜尋。如果停用切面搜尋,您嘗試存取 /facet-search 端點時,Meilisearch 會傳回錯誤。

    取得切面搜尋設定

    GET/indexes/{index_uid}/settings/facet-search

    取得索引的切面搜尋設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/INDEX_UID/settings/facet-search'
    回應:200 OK
    {
      "facetSearch": true
    }
    

    更新切面搜尋設定

    PUT/indexes/{index_uid}/settings/facet-search

    更新索引的切面搜尋設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    <Boolean>
    

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/INDEX_UID/settings/facet-search' \
      -H 'Content-Type: application/json' \
      --data-binary 'false'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "INDEX_UID",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2024-07-19T22:33:18.523881Z"
    }
    

    使用傳回的 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設切面搜尋設定

    DELETE/indexes/{index_uid}/settings/facet-search

    將索引的切面搜尋重設為預設設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/INDEX_UID/settings/facet-search'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "INDEX_UID",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2024-07-19T22:35:33.723983Z"
    }
    

    使用傳回的 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    前綴搜尋是指 Meilisearch 比對以特定查詢詞開頭的文件,而不是僅比對完全符合的文件的過程。預設情況下,這是在索引期間發生的資源密集型操作。

    使用 prefixSearch 來變更前綴搜尋的運作方式。它接受下列字串之一

    取得前綴搜尋設定

    GET/indexes/{index_uid}/settings/prefix-search

    取得索引的前綴搜尋設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/INDEX_UID/settings/prefix-search'
    回應:200 OK
    {
      "prefixSearch": "indexingTime"
    }
    

    更新前綴搜尋設定

    PUT/indexes/{index_uid}/settings/prefix-search

    更新索引的前綴搜尋設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    "indexingTime" | "disabled"
    

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/INDEX_UID/settings/prefix-search' \
      -H 'Content-Type: application/json' \
      --data-binary '"disabled"'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "INDEX_UID",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2024-07-19T22:33:18.523881Z"
    }
    

    使用傳回的 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設前綴搜尋設定

    DELETE/indexes/{index_uid}/settings/prefix-search

    將索引的前綴搜尋重設為預設設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/INDEX_UID/settings/facet-search'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "INDEX_UID",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2024-07-19T22:35:33.723983Z"
    }
    

    使用傳回的 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    排名規則

    排名規則是內建規則,可根據特定條件對搜尋結果進行排名。它們會按照它們在 rankingRules 陣列中出現的順序套用。

    若要深入了解排名規則,請參閱我們的專屬指南。

    排名規則陣列

    名稱描述
    "words"根據比對的查詢詞數量遞減對結果進行排序
    "typo"根據錯字數量遞增對結果進行排序
    "proximity"根據比對的查詢詞之間的距離遞增對結果進行排序
    "attribute"根據屬性排名順序對結果進行排序
    "sort"根據查詢時決定的參數對結果進行排序
    "exactness"根據比對的單字與查詢單字的相似性對結果進行排序

    預設順序

    [
      "words",
      "typo",
      "proximity",
      "attribute",
      "sort",
      "exactness"
    ]
    

    取得排名規則

    GET/indexes/{index_uid}/settings/ranking-rules

    取得索引的排名規則。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/movies/settings/ranking-rules'
    回應:200 Ok
    [
      "words",
      "typo",
      "proximity",
      "attribute",
      "sort",
      "exactness",
      "release_date:desc"
    ]
    

    更新排名規則

    PUT/indexes/{index_uid}/settings/ranking-rules

    更新索引的排名規則。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    [<String>, <String>, …]
    

    包含依重要性排序的排名規則的陣列。

    若要建立自訂排名規則,請提供一個屬性,後接一個冒號 (:),以及 asc (表示遞增順序) 或 desc (表示遞減順序)。

    警告

    如果某些文件不包含自訂排名規則中定義的屬性,則排名規則的應用未定義,並且搜尋結果可能不會依您預期的方式排序。

    請確保自訂排名規則中使用的任何屬性都存在於您的所有文件中。例如,如果您設定自訂排名規則 desc(year),請確保您的所有文件都包含屬性 year

    若要深入了解排名規則,請參閱我們的專屬指南。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/movies/settings/ranking-rules' \
      -H 'Content-Type: application/json' \
      --data-binary '[
        "words",
        "typo",
        "proximity",
        "attribute",
        "sort",
        "exactness",
        "release_date:asc",
        "rank:desc"
      ]'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設排名規則

    DELETE/indexes/{index_uid}/settings/ranking-rules

    將索引的排名規則重設為其預設值

    提示

    重設排名規則與移除排名規則不同。若要移除排名規則,請使用更新排名規則端點

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/movies/settings/ranking-rules'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    可搜尋的屬性

    會在 searchableAttributes 清單中搜尋與屬性相關聯的值,以尋找符合的查詢字詞。清單的順序也決定了屬性排名順序

    預設情況下,searchableAttributes 陣列等於資料集中的所有欄位。此行為以值 ["*"] 表示。

    警告

    更新可搜尋的屬性將會重新索引索引中的所有文件,這可能需要一些時間。我們建議您先更新索引設定,然後再新增文件,因為這樣可以減少 RAM 的消耗。

    若要深入了解可搜尋的屬性,請參閱我們的專屬指南。

    取得可搜尋的屬性

    GET/indexes/{index_uid}/settings/searchable-attributes

    取得索引的可搜尋屬性。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/movies/settings/searchable-attributes'
    回應:200 Ok
    [
      "title",
      "overview",
      "genres",
      "release_date.year"
    ]
    

    更新可搜尋的屬性

    PUT/indexes/{index_uid}/settings/searchable-attributes

    更新索引的可搜尋屬性。

    警告

    由於實作錯誤,手動更新 searchableAttributes 將會變更 JSON 回應中顯示的文件欄位順序。此行為不一致,將會在未來的版本中修正。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    [<String>, <String>, …]
    

    字串陣列。每個字串都應該是所選索引中存在的屬性。陣列應該以重要性順序給定:從最重要的屬性到最不重要的屬性。

    如果屬性包含物件,您可以使用點符號將其一個或多個索引鍵設定為此設定的值:"searchableAttributes": ["release_date.year"]

    警告

    如果欄位不存在,則不會擲回錯誤。

    若要深入了解可搜尋的屬性,請參閱我們的專屬指南。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/movies/settings/searchable-attributes' \
      -H 'Content-Type: application/json' \
      --data-binary '[
        "title",
        "overview",
        "genres"
      ]'

    在這個範例中,title 欄位中有相符項目的文件,會比 overview 欄位中有相符項目的文件更具相關性。

    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設可搜尋屬性

    DELETE/indexes/{index_uid}/settings/searchable-attributes

    將索引的可搜尋屬性重設為預設值。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/movies/settings/searchable-attributes'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    搜尋截止時間

    設定搜尋查詢的最長持續時間。Meilisearch 會中斷任何超過截止時間值的搜尋。

    預設情況下,Meilisearch 會在 1500 毫秒後中斷搜尋。

    取得搜尋截止時間

    GET/indexes/{index_uid}/settings/search-cutoff-ms

    取得索引的搜尋截止時間值。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/movies/settings/search-cutoff-ms'
    回應:200 Ok
    null
    

    更新搜尋截止時間

    PUT/indexes/{index_uid}/settings/search-cutoff-ms

    更新索引的搜尋截止時間值。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    150
    

    一個整數,表示以毫秒為單位的截止時間值。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/movies/settings/search-cutoff-ms' \
      -H 'Content-Type: application/json' \
      --data-binary '150'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2023-03-21T06:33:41.000000Z"
    }
    

    使用此 taskUid 以取得更多關於任務狀態的詳細資訊。

    重設搜尋截止時間

    DELETE/indexes/{index_uid}/settings/search-cutoff-ms

    將索引的搜尋截止時間值重設為其預設值 null。這表示截止時間為 1500 毫秒。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/movies/settings/search-cutoff-ms'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2023-03-21T07:05:16.000000Z"
    }
    

    分隔符號標記

    將字串設定為自訂分隔符號標記,以指示單字在哪裡結束和開始。

    separatorTokens 清單中的標記會新增到Meilisearch 的預設分隔符號清單之上。若要從預設清單中移除分隔符號,請使用nonSeparatorTokens 設定

    取得分隔符號標記

    GET/indexes/{index_uid}/settings/separator-tokens

    取得索引的自訂分隔符號標記清單。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/articles/settings/separator-tokens'
    回應:200 Ok
    []
    

    更新分隔符號標記

    PUT/indexes/{index_uid}/settings/separator-tokens

    更新索引的自訂分隔符號標記清單。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    ["|", "&hellip;"]
    

    一個字串陣列,每個字串都表示一個單字分隔符號。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/articles/settings/separator-tokens' \
      -H 'Content-Type: application/json'  \
      --data-binary '["|", "&hellip;"]'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    使用此 taskUid 以取得更多關於任務狀態的詳細資訊。

    重設分隔符號標記

    DELETE/indexes/{index_uid}/settings/separator-tokens

    將索引的自訂分隔符號標記清單重設為其預設值 []

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/articles/settings/separator-tokens'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    使用此 taskUid 以取得更多關於任務狀態的詳細資訊。

    非分隔符號標記

    從 Meilisearch 的預設單字分隔符號清單中移除標記。

    取得非分隔符號標記

    GET/indexes/{index_uid}/settings/non-separator-tokens

    取得索引的非分隔符號標記清單。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/articles/settings/non-separator-tokens'
    回應:200 Ok
    []
    

    更新非分隔符號標記

    PUT/indexes/{index_uid}/settings/non-separator-tokens

    更新索引的非分隔符號標記清單。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    ["@", "#"]
    

    一個字串陣列,每個字串都表示單字分隔符號清單中存在的標記。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/articles/settings/non-separator-tokens' \
      -H 'Content-Type: application/json'  \
      --data-binary '["@", "#"]'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    使用此 taskUid 以取得更多關於任務狀態的詳細資訊。

    重設非分隔符號標記

    DELETE/indexes/{index_uid}/settings/non-separator-tokens

    將索引的非分隔符號標記清單重設為其預設值 []

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/articles/settings/separator-tokens'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    使用此 taskUid 以取得更多關於任務狀態的詳細資訊。

    可排序屬性

    在使用sort 搜尋參數對搜尋結果進行排序時可以使用的屬性。

    警告

    更新可排序屬性將會重新索引索引中的所有文件,這可能需要一些時間。我們建議您先更新索引設定,然後再新增文件,因為這樣可以減少 RAM 的消耗。

    若要深入了解可排序屬性,請參閱我們的專門指南。

    取得可排序屬性

    GET/indexes/{index_uid}/settings/sortable-attributes

    取得索引的可排序屬性。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/books/settings/sortable-attributes'
    回應:200 Ok
    [
      "price",
      "author.surname"
    ]
    

    更新可排序屬性

    PUT/indexes/{index_uid}/settings/sortable-attributes

    更新索引的可排序屬性清單。

    您可以在我們的專門指南中閱讀更多關於查詢時排序的資訊。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    [<String>, <String>, …]
    

    字串陣列。每個字串都應該是選定索引中存在的屬性。

    如果屬性包含物件,您可以使用點表示法將其一個或多個鍵設定為此設定的值:"sortableAttributes": ["author.surname"]

    警告

    如果欄位不存在,則不會擲回錯誤。

    若要深入了解可排序屬性,請參閱我們的專門指南。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/books/settings/sortable-attributes' \
      -H 'Content-Type: application/json' \
      --data-binary '[
        "price",
        "author"
      ]'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設可排序屬性

    DELETE/indexes/{index_uid}/settings/sortable-attributes

    將索引的可排序屬性清單重設回其預設值。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/books/settings/sortable-attributes'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    停用詞

    新增到 stopWords 清單中的單字將在未來的搜尋查詢中被忽略。

    警告

    更新停用詞將會重新索引索引中的所有文件,這可能需要一些時間。我們建議您先更新索引設定,然後再新增文件,因為這樣可以減少 RAM 的消耗。

    提示

    停用詞與資料集中使用的語言密切相關。例如,大多數包含英文文件的資料集會包含無數個 theof。義大利文資料集則會受益於忽略像 alail 之類的單字。

    這個由一位法國開發人員維護的網站提供了不同語言中可能的停用詞清單。請注意,根據您的資料集和使用案例,您需要調整這些清單以獲得最佳結果。

    取得停用詞

    GET/indexes/{index_uid}/settings/stop-words

    取得索引的停用詞清單。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/movies/settings/stop-words'
    回應:200 Ok
    [
      "of",
      "the",
      "to"
    ]
    

    更新停用詞

    PUT/indexes/{index_uid}/settings/stop-words

    更新索引的停用詞清單。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    [<String>, <String>, …]
    

    一個字串陣列。每個字串都應為一個單字。

    如果已存在停用詞清單,它將被覆寫(取代)。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/movies/settings/stop-words' \
      -H 'Content-Type: application/json' \
      --data-binary '[
        "the",
        "of",
        "to"
      ]'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設停用詞

    DELETE/indexes/{index_uid}/settings/stop-words

    將索引的停用詞清單重設為其預設值。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/movies/settings/stop-words'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    同義詞

    synonyms 物件包含單字及其各自的同義詞。在 Meilisearch 中,同義詞在計算搜尋結果時被視為與其相關的單字相等。

    若要深入了解同義詞,請參閱我們的專門指南。

    取得同義詞

    GET/indexes/{index_uid}/settings/synonyms

    取得索引的同義詞清單。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/movies/settings/synonyms'
    回應:200 OK
    {
      "wolverine": [
        "xmen",
        "logan"
      ],
      "logan": [
        "wolverine",
        "xmen"
      ],
      "wow": [
        "world of warcraft"
      ]
    }
    

    更新同義詞

    PUT/indexes/{index_uid}/settings/synonyms

    更新索引的同義詞清單。同義詞會被正規化

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    {
      <String>: [<String>, <String>, …],
      …
    }
    

    一個物件,包含所有同義詞及其相關的單字。在陣列中加入相關的單字以設定單字的同義詞。

    若要深入了解同義詞,請參閱我們的專門指南。

    範例

    curl \
      -X PUT 'https://127.0.0.1:7700/indexes/movies/settings/synonyms' \
      -H 'Content-Type: application/json' \
      --data-binary '{
        "wolverine": [
          "xmen",
          "logan"
        ],
        "logan": [
          "wolverine",
          "xmen"
        ],
        "wow": ["world of warcraft"]
      }'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    重設同義詞

    DELETE/indexes/{index_uid}/settings/synonyms

    將索引的同義詞清單重設為其預設值。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/movies/settings/synonyms'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "movies",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2021-08-11T09:25:53.000000Z"
    }
    

    您可以使用此 taskUid 來取得有關 任務狀態 的更多詳細資訊。

    錯字容忍度

    錯字容錯功能可幫助使用者在搜尋查詢包含拼寫錯誤或錯字時,仍能找到相關結果。此設定可讓您設定錯字的最小字詞大小,並針對特定字詞或屬性停用錯字容錯功能。

    若要深入瞭解錯字容錯功能,請參閱我們的專門指南。

    錯字容錯物件

    名稱類型預設值描述
    已啟用布林值true是否啟用錯字容錯功能
    minWordSizeForTypos.oneTypo整數5接受 1 個錯字的最小字詞大小;必須介於 0twoTypos 之間
    minWordSizeForTypos.twoTypos整數9接受 2 個錯字的最小字詞大小;必須介於 oneTypo255 之間
    disableOnWords字串陣列停用錯字容錯功能的字詞陣列
    disableOnAttributes字串陣列停用錯字容錯功能的屬性陣列

    取得錯字容錯設定

    GET/indexes/{index_uid}/settings/typo-tolerance

    取得索引的錯字容錯設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/books/settings/typo-tolerance'
    回應:200 OK
    {
      "enabled": true,
      "minWordSizeForTypos": {
        "oneTypo": 5,
        "twoTypos": 9
      },
      "disableOnWords": [],
      "disableOnAttributes": []
    }
    

    更新錯字容錯設定

    PATCH/indexes/{index_uid}/settings/typo-tolerance

    部分更新索引的錯字容錯設定。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    {
      "enabled": <Boolean>,
      "minWordSizeForTypos": {
        "oneTypo": <Integer>,
        "twoTypos": <Integer>
      },
      "disableOnWords": [<String>, <String>, …],
      "disableOnAttributes": [<String>, <String>, …]
    }
    
    名稱類型預設值描述
    已啟用布林值true是否啟用錯字容錯功能
    minWordSizeForTypos.oneTypo整數5接受 1 個錯字的最小字詞大小;必須介於 0twoTypos 之間
    minWordSizeForTypos.twoTypos整數9接受 2 個錯字的最小字詞大小;必須介於 oneTypo255 之間
    disableOnWords字串陣列停用錯字容錯功能的字詞陣列
    disableOnAttributes字串陣列停用錯字容錯功能的屬性陣列

    範例

    curl \
      -X PATCH 'https://127.0.0.1:7700/indexes/books/settings/typo-tolerance' \
      -H 'Content-Type: application/json' \
      --data-binary '{
        "minWordSizeForTypos": {
          "oneTypo": 4,
          "twoTypos": 10
        },
        "disableOnAttributes": ["title"]
      }'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2022-04-14T20:56:44.991039Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    重設錯字容錯設定

    DELETE/indexes/{index_uid}/settings/typo-tolerance

    將索引的錯字容錯設定重設為預設值

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/books/settings/typo-tolerance'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2022-04-14T20:53:32.863107Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    嵌入器 (實驗性)

    嵌入器將文件和查詢轉換為向量嵌入。您必須設定至少一個嵌入器才能使用 AI 驅動的搜尋。

    嵌入器物件

    嵌入器物件最多可包含 256 個嵌入器物件。每個嵌入器物件都必須指派一個獨特的名稱

    {
      "default": {
        "source": "huggingFace",
        "model": "BAAI/bge-base-en-v1.5",
        "documentTemplate": "A movie titled '{{doc.title}}' whose description starts with {{doc.overview|truncatewords: 20}}"
      },
      "openai": {
        "source": "openAi",
        "apiKey": "OPENAI_API_KEY",
        "model": "text-embedding-3-small",
        "documentTemplate": "A movie titled {{doc.title}} whose description starts with {{doc.overview|truncatewords: 20}}",
      }
    }
    

    這些嵌入器物件可能包含下列欄位

    名稱類型預設值描述
    source字串將從文件中產生嵌入的第三方工具。必須是 openAihuggingFaceollamarestuserProvided
    url字串https://127.0.0.1:11434/api/embeddingsMeilisearch 在查詢嵌入器時會連線的 URL
    apiKey字串Meilisearch 應隨每個對嵌入器的請求傳送的驗證權杖。如果不存在,Meilisearch 會嘗試從環境變數讀取
    model字串您的嵌入器在產生向量時使用的模型
    documentTemplate字串{% for field in fields %} {% if field.is_searchable and not field.value == nil %}{{ field.name }}: {{ field.value }} {% endif %} {% endfor %}定義 Meilisearch 傳送至嵌入器的資料的範本
    documentTemplateMaxBytes整數400轉譯文件範本允許的最大大小
    dimensions整數所選模型中的維度數。如果未提供,Meilisearch 會嘗試推斷此值
    revision字串模型修訂雜湊
    distribution物件描述搜尋結果的自然分佈。必須包含兩個欄位,meansigma,每個欄位包含介於 01 之間的數值
    request物件代表 Meilisearch 向遠端嵌入器發出請求的 JSON 值
    response物件代表 Meilisearch 預期從遠端嵌入器收到的回應的 JSON 值
    binaryQuantized布林值一旦設定為 true,將不可逆地將所有向量維度轉換為 1 位元值

    取得嵌入器設定

    GET/indexes/{index_uid}/settings/embedders

    取得為索引設定的嵌入器。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X GET 'https://127.0.0.1:7700/indexes/INDEX_NAME/settings/embedders'
    回應:200 OK
    {
      "default": {
        "source":  "openAi",
        "apiKey": "OPENAI_API_KEY",
        "model": "text-embedding-3-small",
        "documentTemplate": "A movie titled {{doc.title}} whose description starts with {{doc.overview|truncatewords: 20}}",
        "dimensions": 1536
      }
    }
    

    更新嵌入器設定

    PATCH/indexes/{index_uid}/settings/embedders

    部分更新索引的嵌入器設定。當此設定更新時,Meilisearch 可能會重新索引所有文件並重新產生其嵌入。

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    主體

    {
      "default": {
        "source": <String>,
        "url": <String>,
        "apiKey": <String>,
        "model": <String>,
        "documentTemplate": <String>,
        "documentTemplateMaxBytes": <Integer>,
        "dimensions": <Integer>,
        "revision": <String>,
        "distribution": {
          "mean": <Float>,
          "sigma": <Float>
        },
        "request": {},
        "response": {},
        "headers": {},
        "binaryQuantized": <Boolean>
      }
    }
    

    將嵌入器設定為 null 以從嵌入器清單中移除它。

    source

    使用 source 設定嵌入器的來源。下列嵌入器可以自動為文件和查詢產生向量

    此外,使用 rest 可使用任何提供 REST API 的嵌入器自動產生嵌入。

    您也可以設定 userProvided 嵌入器。在這種情況下,您必須在文件的 _vector 欄位中手動包含向量資料。您也必須手動產生搜尋查詢的向量。

    此欄位為必要欄位。

    url

    Meilisearch 會查詢 url 以產生查詢和文件的向量嵌入。url 必須指向與 REST 相容的嵌入器。您也可以使用 url 來使用 Proxy,例如從 Proxy 後面鎖定 openAi 時。

    使用 rest 嵌入器時,此欄位為必要欄位。

    使用 ollamaopenAi 嵌入器時,此欄位為選用欄位。

    此欄位與 huggingFaceuserProvided 嵌入器不相容。

    apiKey

    Meilisearch 應隨每個對嵌入器的請求傳送的驗證權杖。

    如果使用受保護的 rest 嵌入器,此欄位為必要欄位。

    此欄位對於 openAIollama 嵌入器是可選的。如果您未指定 apiKey,Meilisearch 會嘗試分別從環境變數 OPENAI_API_KEYMEILI_OLLAMA_URL 讀取它。

    此欄位與 huggingFaceuserProvided 嵌入器不相容。

    model

    您的嵌入器在產生向量時使用的模型。這些是 Meilisearch 支援的官方支援模型

    其他模型,例如 HuggingFace 的 BERT 模型 或 Ollama 和 REST 嵌入器提供的模型,也可能與 Meilisearch 相容。

    此欄位對於 Ollama 嵌入器為必要欄位。

    此欄位對於 openAihuggingFace 為選用欄位。預設情況下,Meilisearch 分別使用 text-embedding-3-smallBAAI/bge-base-en-v1.5

    此欄位與 restuserProvided 嵌入器不相容。

    documentTemplate

    documentTemplate 是一個包含 Liquid 範本的字串。Meilisearch 會為每個文件內插範本,並將產生的文字傳送至嵌入器。然後,嵌入器會根據此文字產生文件向量。

    您可以使用下列內容值

    如果文件中不存在 field,則其 valuenil

    為了獲得最佳結果,請建立僅包含高度相關資料的簡短範本。如果使用長欄位,請考慮截斷它。如果您沒有手動設定,documentTemplate 將包含所有可搜尋且非空的檔案欄位。這可能會導致效能和相關性欠佳。

    此欄位為選用欄位,但強烈建議所有嵌入器都使用。

    documentTemplateMaxBytes

    轉譯文件範本的最大大小。較長的文字會被截斷以符合設定的限制。

    documentTemplateMaxBytes 必須是整數。預設值為 400

    此欄位對於所有嵌入器為選用欄位。

    dimensions

    所選模型中的維度數。如果未提供,Meilisearch 會嘗試推斷此值。

    在大多數情況下,dimensions 應該與您所選模型的精確值相同。將 dimensions 設定為低於模型的值可能會帶來效能改善,並且僅在下列 OpenAI 模型中支援

    此欄位對於 userProvided 嵌入器為必要欄位。

    此欄位對於 openAihuggingFaceollamarest 嵌入器為選用欄位。

    revision

    使用此欄位可使用模型的特定修訂版本。

    此欄位對於 huggingFace 嵌入器為選用欄位。

    此欄位與所有其他嵌入器不相容。

    request

    request 必須是具有與您必須傳送至 rest 嵌入器的請求相同結構和資料的 JSON 物件。

    包含 Meilisearch 應傳送至嵌入器的輸入文字的欄位必須替換為 "{{text}}"

    {
      "source": "rest",
      "request": {
        "prompt": "{{text}}"},}
    

    如果在單一請求中傳送多個文件,請將輸入欄位替換為 ["{{text}}", "{{..}}"]

    {
      "source": "rest",
      "request": {
        "prompt": ["{{text}}", "{{..}}"]},}
    

    使用 rest 嵌入器時,此欄位為必要欄位。

    此欄位與所有其他嵌入器不相容。

    response

    response 必須是具有與您預期從 rest 嵌入器接收的回應相同結構和資料的 JSON 物件。

    包含嵌入本身的欄位必須替換為 "{{embedding}}"

    {
      "source": "rest",
      "response": {
        "data": "{{embedding}}"},}
    

    如果單一回應包含多個嵌入,則包含嵌入本身的欄位必須是一個具有兩個項目的陣列。一個必須宣告單一嵌入的位置和結構,而第二個項目應該是 "{{..}}"

    {
      "source": "rest",
      "response": {
        "data": [
          {
            "embedding": "{{embedding}}"
          },
          "{{..}}"
        ]},}
    

    使用 rest 嵌入器時,此欄位為必要欄位。

    此欄位與所有其他嵌入器不相容。

    distribution

    基於數學原因,語義搜尋結果的 _rankingScore 往往會集中在一個平均值附近,該平均值取決於使用的嵌入器和模型。這可能導致相關的語義結果被低估,而不相關的語義結果則相較於關鍵字搜尋結果被高估。

    配置嵌入器時,使用 distribution 來校正語義結果的 _rankingScore,進行仿射轉換。

    curl \
      -X PATCH 'https://127.0.0.1:7700/indexes/INDEX_NAME/settings' \
      -H 'Content-Type: application/json' \
      --data-binary '{
        "embedders": {
          "default": {
            "source":  "huggingFace",
            "model": "MODEL_NAME",
            "distribution": {
              "mean": 0.7,
              "sigma": 0.3
            }
          }
        }
      }'
    

    配置 distribution 需要經過一定程度的試驗和錯誤,您必須執行語義搜尋並監控結果。根據它們的 rankingScore 和相關性,為該索引添加觀察到的 meansigma 值。

    distribution 是一個與所有嵌入器來源相容的可選欄位。它必須是一個包含兩個欄位的物件:

    更改 distribution 不會觸發重新索引操作。

    標頭

    headers 必須是一個 JSON 物件,其鍵代表在發送給嵌入器的請求中要發送的其他標頭的名稱,其值代表這些額外標頭的值。

    預設情況下,Meilisearch 會在所有發送給 rest 嵌入器的請求中發送以下標頭:

    如果 headers 包含這些欄位中的一個,則明確宣告的值優先於預設值。

    當使用 rest 嵌入器時,此欄位是可選的。

    此欄位與所有其他嵌入器不相容。

    binaryQuantized

    當設定為 true 時,通過用 1 位元值表示每個維度來壓縮向量。這會降低語義搜尋結果的相關性,但可以大幅縮減資料庫大小。

    當處理大型 Meilisearch 專案時,此選項可能很有用。如果您的專案包含超過一百萬份文件並使用超過 1400 個維度的模型,請考慮啟用它。

    二元量化是一個不可逆的過程

    啟用 binaryQuantized 是不可逆的。 一旦啟用,Meilisearch 會轉換所有向量並捨棄所有不符合 1 位元的向量資料。恢復向量原始值的唯一方法是在新的嵌入器中重新向量化整個索引。

    範例

    curl \
      -X PATCH 'https://127.0.0.1:7700/indexes/INDEX_NAME/settings' \
      -H 'Content-Type: application/json' \
      --data-binary '{
        "embedders": {
          "default": {
            "source":  "openAi",
            "apiKey": "anOpenAiApiKey",
            "model": "text-embedding-3-small",
            "documentTemplate": "A document titled '{{doc.title}}' whose description starts with {{doc.overview|truncatewords: 20}}"
          }
        }
      }'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "kitchenware",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2024-05-11T09:33:12.691402Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。

    重設嵌入器設定

    DELETE/indexes/{index_uid}/settings/embedders

    從您的索引中移除所有嵌入器。

    要移除單個嵌入器,請使用更新嵌入器設定端點並將目標嵌入器設定為 null

    路徑參數

    名稱類型描述
    index_uid *字串請求索引的 uid

    範例

    curl \
      -X DELETE 'https://127.0.0.1:7700/indexes/INDEX_NAME/settings/embedders'
    回應:202 Accepted
    {
      "taskUid": 1,
      "indexUid": "books",
      "status": "enqueued",
      "type": "settingsUpdate",
      "enqueuedAt": "2022-04-14T20:53:32.863107Z"
    }
    

    您可以使用傳回的 taskUid 來取得更多關於 任務狀態 的詳細資訊。