使用 /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,
  "embedders": {}
}

所有设置

此路由允许您一次性检索、配置或重置索引的所有设置。

获取设置

GET
/indexes/{index_uid}/settings

获取索引的设置。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/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,
  "embedders": {}
}

更新设置

PATCH
/indexes/{index_uid}/settings

更新索引的设置。

null 传递给索引设置会将其重置为默认值。

设置路由中的更新是部分更新。这意味着请求体中未提供的任何参数将保持不变。

如果提供的索引不存在,则会创建它。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

名称类型默认值描述
dictionary字符串数组Meilisearch 应解析为单个术语的字符串列表
displayedAttributes字符串数组所有属性:["*"]返回文档中显示的字段
distinctAttribute字符串null搜索返回给定字段具有唯一(不同)值的文档
faceting对象默认对象分面设置
filterableAttributes字符串或对象数组用作过滤器和分面的属性
pagination对象默认对象分页设置
proximityPrecision字符串"byWord"计算临近排名规则时的精度级别
facetSearch布尔值true启用或禁用 分面搜索 功能
prefixSearch字符串"indexingTime"Meilisearch 何时应只返回与查询开头匹配的结果
rankingRules字符串数组["words",
"typo",
"proximity",
"attribute",
"sort",
"exactness"]
重要性排序的排名规则列表
searchableAttributes字符串数组所有属性:["*"]按重要性排序的搜索匹配查询词的字段
searchCutoffMs整数null,或 1500ms搜索查询的最大持续时间
separatorTokens字符串数组界定术语起止的字符列表
nonSeparatorTokens字符串数组不界定术语起止的字符列表
sortableAttributes字符串数组排序搜索结果时使用的属性
stopWords字符串数组Meilisearch 在搜索查询中忽略的词语列表
synonyms对象被视为相似的相关词语列表
typoTolerance对象默认对象错别字容忍设置
embedders对象中的对象默认对象执行基于语义的搜索查询所需的嵌入器

示例

curl \
  -X PATCH 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/books/settings/dictionary'
响应:200 OK
[]

更新词典

PUT
/indexes/{index_uid}/settings/dictionary

更新索引的用户定义词典。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

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

示例

curl \
  -X PUT 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/movies/settings/displayed-attributes'
响应:202 Accepted
{
  "taskUid": 1,
  "indexUid": "movies",
  "status": "enqueued",
  "type": "settingsUpdate",
  "enqueuedAt": "2021-08-11T09:25:53.000000Z"
}

您可以使用此 taskUid 获取有关任务状态的更多详细信息。

唯一属性

唯一属性是指在返回文档中其值始终唯一的字段。

更新唯一属性将重新索引索引中的所有文档,这可能需要一些时间。我们建议先更新索引设置,然后再添加文档,因为这可以减少内存消耗。

要了解有关唯一属性的更多信息,请参阅我们的专用指南。

获取唯一属性

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

获取索引的唯一属性。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/shoes/settings/distinct-attribute'
响应:202 Accepted
{
  "taskUid": 1,
  "indexUid": "movies",
  "status": "enqueued",
  "type": "settingsUpdate",
  "enqueuedAt": "2021-08-11T09:25:53.000000Z"
}

您可以使用此 taskUid 获取有关任务状态的更多详细信息。

分面

使用 Meilisearch,您可以创建分面搜索界面。此设置允许您

  • 定义 facets 搜索参数返回的最大值数量
  • 按值计数或字母数字顺序排序分面值

要了解有关分面的更多信息,请参阅我们的专用指南。

分面对象

名称类型默认值描述
maxValuesPerFacet整数100每个分面返回的最大分面值数量。值按升序词典顺序排序
sortFacetValuesBy对象所有分面值均按升序字母数字顺序排序 ("*": "alpha")自定义分面顺序,按降序值计数 (count) 或升序字母数字顺序 (alpha) 排序

获取分面设置

GET
/indexes/{index_uid}/settings/faceting

获取索引的分面设置。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/indexes/books/settings/faceting'
响应:200 OK
{
  "maxValuesPerFacet": 100,
  "sortFacetValuesBy": {
    "*": "alpha"
  }
}

更新分面设置

PATCH
/indexes/{index_uid}/settings/faceting

部分更新索引的分面设置。请求体中未提供的任何参数将保持不变。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

{
  "maxValuesPerFacet": <Integer>,
  "sortFacetValuesBy": {
      <String>: "count",
      <String>: "alpha"
  }
}
名称类型默认值描述
maxValuesPerFacet整数100每个分面返回的最大分面值数量。值按升序词典顺序排序
sortFacetValuesBy对象所有分面值均按升序字母数字顺序排序 ("*": "alpha")自定义分面顺序,按降序值计数(count) 或升序字母数字顺序 (alpha) 排序

假设查询的搜索结果中包含 colors 分面的三个值:bluegreenred。如果您将 maxValuesPerFacet 设置为 2,Meilisearch 将在响应体的 facetDistribution 对象中仅返回 bluegreen

maxValuesPerFacet 设置为高值可能会对性能产生负面影响。

示例

以下代码示例将 maxValuesPerFacet 设置为 2,按降序计数对 genres 分面进行排序,并按升序字母数字顺序对所有其他分面进行排序

curl \
  -X PATCH 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/books/settings/faceting'
响应:200 OK
{
  "taskUid": 1,
  "indexUid": "books",
  "status": "enqueued",
  "type": "settingsUpdate",
  "enqueuedAt": "2022-04-14T20:53:32.863107Z"
}

您可以使用返回的 taskUid 获取有关任务状态的更多详细信息。

可过滤属性

filterableAttributes 列表中的属性可用作过滤器分面

更新可过滤属性将重新索引索引中的所有文档,这可能需要一些时间。为减少内存消耗,请先更新索引设置,然后添加文档。

可过滤属性对象

filterableAttributes 可以是字符串数组或可过滤属性对象数组。

可过滤属性对象必须包含以下字段

名称类型默认值描述
attributePatterns字符串数组[]指示可过滤字段的字符串列表
features对象{"facetSearch": false, "filters": {"equality": true, "comparison": false}列出为指定属性启用的过滤器类型

attributePatterns

属性模式可以以 * 通配符开头或结尾,以匹配多个字段:customer_*, attribute*

features

features 允许您决定为指定属性启用哪些过滤器功能。它接受以下字段:

  • facetSearch:是否为指定属性启用分面搜索。布尔值,默认为 false
  • filter:列出指定属性的过滤器类型。必须是对象并接受以下字段:
    • equality:启用 =, !=, IN, EXISTS, IS NULL, IS EMPTY, NOT, ANDOR。布尔值,默认为 true
    • comparison:启用 >, >=, <, <=, TO, EXISTS, IS NULL, IS EMPTY, NOT, ANDOR。布尔值,默认为 false

计算 comparison 过滤器是资源密集型操作。禁用它们可能会提高搜索和索引性能。equality 过滤器使用较少资源,对性能影响有限。

可过滤属性和保留属性

使用简单字符串语法匹配保留属性。Meilisearch 保留字段始终以下划线 (_) 为前缀,例如 _geo_vector

如果设置为可过滤属性,保留属性将忽略 features 字段并自动激活所有搜索功能。保留字段不会被通配符 attributePatterns(例如 _*)匹配。

获取可过滤属性

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

获取索引的可过滤属性。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/indexes/movies/settings/filterable-attributes'
响应:200 Ok
[
  "genres",
  "director",
  "release_date.year"
]

更新可过滤属性

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

更新索引的可过滤属性列表。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

[<String>, <String>, …]

字符串数组,包含可在查询时用作过滤器的属性。当使用字符串数组格式时,为指定属性启用所有过滤器类型。

您也可以使用对象数组

[
  {
    "attributePatterns": [<String>, <String>, …],
    "features": {
      "facetSearch": <Boolean>,
      "filter": {
        "equality": <Boolean>,
        "comparison": <Boolean>
      }
    }
  }
]

如果指定字段不存在,Meilisearch 将静默忽略它。

如果属性包含对象,您可以使用点表示法将其一个或多个键设置为此设置的值:"filterableAttributes": ["release_date.year"]"attributePatterns": ["release_date.year"]

示例

curl \
  -X PUT 'MEILISEARCH_URL/indexes/movies/settings/filterable-attributes' \
  -H 'Content-Type: application/json' \
  --data-binary '[
    "genres",
    "director",
    {
      "attributePatterns": ["*_ratings"],
      "features": {
        "facetSearch": false,
        "filters": {
          "equality": true,
          "comparison": false
        }
      }
    }
  ]'
响应: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 'MEILISEARCH_URL/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 具有相同目的:当 Meilisearch 的语言自动检测未按预期工作时,明确声明搜索中使用的语言。

如果您认为 Meilisearch 因查询文本而检测到不正确的语言,请使用 locales 明确设置搜索语言。

如果您认为 Meilisearch 因文档而检测到不正确的语言,请使用 localizedAttributes 在索引级别明确设置文档语言。

为了完全控制 Meilisearch 在索引和搜索时检测语言的方式,请同时设置 localeslocalizedAttributes

本地化属性对象

localizedAttributes 必须是区域设置对象的数组。其默认值为 []

区域设置对象必须包含以下字段

名称类型默认值描述
locales字符串数组[]指示一个或多个 ISO-639 区域设置的字符串列表
attributePatterns字符串数组[]指示哪些字段对应于指定区域设置的字符串列表

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 'MEILISEARCH_URL/indexes/INDEX_NAME/settings/localized-attributes'
响应:200 OK
[
  {"locales": ["jpn"], "attributePatterns": ["*_ja"]}
]

更新本地化属性设置

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

更新索引的本地化属性设置。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

[
  {
   "locales": [<String>, …],
   "attributePatterns": [<String>, …],
  }
]
名称类型默认值描述
localizedAttributes对象数组[]为一个或多个属性显式设置特定区域设置

示例

curl \
  -X PUT 'MEILISEARCH_URL/indexes/INDEX_NAME/settings/localized-attributes' \
  -H 'Content-Type: application/json' \
  --data-binary '[
    {"locales": ["jpn"], "attributePatterns": ["*_ja"]}
  ]'
响应:202 Accepted
{
  "taskUid": 1,
  "indexUid": "INDEX_NAME",
  "status": "enqueued",
  "type": "settingsUpdate",
  "enqueuedAt": "2022-04-14T20:56:44.991039Z"
}

您可以使用返回的 taskUid 获取有关任务状态的更多详细信息。

重置本地化属性设置

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

将索引的本地化属性重置为其默认值

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X DELETE 'MEILISEARCH_URL/indexes/INDEX_NAME/settings/localized-attributes'
响应: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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/books/settings/pagination'
响应:202 Accepted
{
  "taskUid": 1,
  "indexUid": "books",
  "status": "enqueued",
  "type": "settingsUpdate",
  "enqueuedAt": "2022-04-14T20:53:32.863107Z"
}

您可以使用返回的 taskUid 获取有关任务状态的更多详细信息。

临近度精度

计算词语之间的距离是资源密集型操作。降低此操作的精度可能会显著提高性能,并且在大多数用例中对结果相关性影响很小。Meilisearch 在根据临近度对结果进行排名以及用户执行短语搜索时使用词语距离。

proximityPrecision 接受以下字符串值之一:

  • "byWord":计算查询词之间的精确距离。精度更高,但可能导致索引时间更长。这是默认设置
  • "byAttribute":确定同一属性中是否存在多个查询词。精度较低,但索引时间较短

获取临近度精度设置

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

获取索引的临近度精度设置。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/indexes/books/settings/proximity-precision'
响应:200 OK
"byWord"

更新临近度精度设置

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

更新索引的分页设置。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

"byWord"|"byAttribute"

示例

curl \
  -X PUT 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/INDEX_UID/settings/facet-search'
响应:200 OK
true

更新分面搜索设置

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

更新索引的分面搜索设置。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

<Boolean>

示例

curl \
  -X PUT 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 更改前缀搜索的工作方式。它接受以下字符串之一:

  • "indexingTime":在索引期间计算前缀搜索。这是默认行为
  • "disabled":不计算前缀搜索。可能加快索引速度,但会严重影响搜索结果相关性

获取前缀搜索设置

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

获取索引的前缀搜索设置。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/indexes/INDEX_UID/settings/prefix-search'
响应:200 OK
"indexingTime"

更新前缀搜索设置

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

更新索引的前缀搜索设置。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

"indexingTime" | "disabled"

示例

curl \
  -X PUT 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 表示降序。

  • 要应用升序排序(结果按值递增排序):attribute_name:asc
  • 要应用降序排序(结果按值递减排序):attribute_name:desc

如果某些文档不包含自定义排名规则中定义的属性,则排名规则的应用是未定义的,搜索结果可能不会按您预期的方式排序。

确保自定义排名规则中使用的任何属性都存在于所有文档中。例如,如果您设置自定义排名规则 desc(year),请确保所有文档都包含属性 year

要了解有关排名规则的更多信息,请参阅我们的专用指南。

示例

curl \
  -X PUT 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 数组等于数据集中所有字段。此行为由值 ["*"] 表示。

更新可搜索属性将重新索引索引中的所有文档,这可能需要一些时间。我们建议先更新索引设置,然后再添加文档,因为这可以减少内存消耗。

要了解有关可搜索属性的更多信息,请参阅我们的专用指南。

获取可搜索属性

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

获取索引的可搜索属性。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/movies/settings/search-cutoff-ms'
响应:200 Ok
null

更新搜索截止时间

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

更新索引的搜索截止时间值。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

150

一个整数,表示以毫秒为单位的截止时间值。

示例

curl \
  -X PUT 'MEILISEARCH_URL/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。这相当于 1500ms 的截止时间。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X DELETE 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/articles/settings/separator-tokens'
响应:200 Ok
[]

更新分隔符标记

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

更新索引的自定义分隔符标记列表。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

["|", "&hellip;"]

字符串数组,每个字符串表示一个单词分隔符。

示例

curl \
  -X PUT 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/articles/settings/non-separator-tokens'
响应:200 Ok
[]

更新非分隔符标记

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

更新索引的非分隔符标记列表。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

请求体

["@", "#"]

字符串数组,每个字符串表示单词分隔符列表中存在的标记。

示例

curl \
  -X PUT 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/articles/settings/separator-tokens'
响应:202 Accepted
{
  "taskUid": 1,
  "indexUid": "movies",
  "status": "enqueued",
  "type": "settingsUpdate",
  "enqueuedAt": "2021-08-11T09:25:53.000000Z"
}

使用此 taskUid 获取有关任务状态的更多详细信息。

可排序属性

在使用sort 搜索参数排序搜索结果时可以使用的属性。

更新可排序属性将重新索引索引中的所有文档,这可能需要一些时间。我们建议先更新索引设置,然后再添加文档,因为这可以减少内存消耗。

要了解有关可排序属性的更多信息,请参阅我们的专用指南。

获取可排序属性

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

获取索引的可排序属性。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/books/settings/sortable-attributes'
响应:202 Accepted
{
  "taskUid": 1,
  "indexUid": "movies",
  "status": "enqueued",
  "type": "settingsUpdate",
  "enqueuedAt": "2021-08-11T09:25:53.000000Z"
}

您可以使用此 taskUid 获取有关任务状态的更多详细信息。

停用词

添加到 stopWords 列表中的词语在未来的搜索查询中将被忽略。

更新停用词将重新索引索引中的所有文档,这可能需要一些时间。我们建议先更新索引设置,然后再添加文档,因为这可以减少内存消耗。

停用词与数据集中使用的语言密切相关。例如,大多数包含英文文档的数据集将有无数次出现 theof。而意大利语数据集将受益于忽略诸如 alail 等词语。

这个由法国开发者维护的网站提供了不同语言的可能停用词列表。请注意,根据您的数据集和用例,您需要调整这些列表以获得最佳结果。

获取停用词

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

获取索引的停用词列表。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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 'MEILISEARCH_URL/indexes/movies/settings/synonyms'
响应:202 Accepted
{
  "taskUid": 1,
  "indexUid": "movies",
  "status": "enqueued",
  "type": "settingsUpdate",
  "enqueuedAt": "2021-08-11T09:25:53.000000Z"
}

您可以使用此 taskUid 获取有关任务状态的更多详细信息。

错别字容忍度

错别字容忍度帮助用户即使在搜索查询包含拼写错误或错别字时也能找到相关结果。此设置允许您配置错别字的最小词长,并禁用特定词语或属性的错别字容忍度。

要了解有关错别字容忍度的更多信息,请参阅我们的专用指南。

错别字容忍对象

名称类型默认值描述
enabled布尔值true是否启用错别字容忍度
minWordSizeForTypos.oneTypo整数5接受 1 个错别字的最小词长;必须介于 0twoTypos 之间
minWordSizeForTypos.twoTypos整数9接受 2 个错别字的最小词长;必须介于 oneTypo255 之间
disableOnWords字符串数组禁用错别字容忍功能的词语数组
disableOnAttributes字符串数组禁用错别字容忍功能的属性数组
disableOnNumbers布尔值false是否禁用或启用数字的错别字容忍度

获取错别字容忍设置

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

获取索引的错别字容忍设置。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/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>, …]
  "disableOnNumbers": <Boolean>,
}
名称类型默认值描述
enabled布尔值true是否启用错别字容忍度
minWordSizeForTypos.oneTypo整数5接受 1 个错别字的最小词长;必须介于 0twoTypos 之间
minWordSizeForTypos.twoTypos整数9接受 2 个错别字的最小词长;必须介于 oneTypo255 之间
disableOnWords字符串数组禁用错别字容忍功能的词语数组
disableOnAttributes字符串数组禁用错别字容忍功能的属性数组
disableOnNumbers布尔值false是否禁用或启用数字的错别字容忍度

示例

curl \
  -X PATCH 'MEILISEARCH_URL/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 'MEILISEARCH_URL/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字符串http://localhost: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 位值
indexingEmbedder对象配置嵌入器以在索引期间向量化文档
searchEmbedder对象配置嵌入器以向量化搜索查询
pooling字符串"useModel"Hugging Face 嵌入器的池化方法

获取嵌入器设置

GET
/indexes/{index_uid}/settings/embedders

获取为索引配置的嵌入器。

路径参数

名称类型描述
index_uid *字符串请求索引的 uid

示例

curl \
  -X GET 'MEILISEARCH_URL/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>,
    "pooling": <String>,
    "indexingEmbedder": {  },
    "searchEmbedder": {  }
  }
}

将嵌入器设置为 null 可将其从嵌入器列表中移除。

source

使用 source 配置嵌入器的来源。来源对应于从您的文档生成嵌入的服务。

Meilisearch 支持以下来源

  • openAi
  • huggingFace
  • ollama
  • rest
  • userProvided
  • composite 实验性

rest 是一个通用来源,与任何提供 REST API 的嵌入提供商兼容。

当您希望手动生成嵌入时,请使用 userProvided。在这种情况下,您必须在文档的 _vectors 字段中包含向量数据。您还必须为搜索查询生成向量。

此字段是强制性的。

复合嵌入器 实验性

选择 composite 以在索引时使用一个嵌入器,在搜索时使用另一个嵌入器。必须与indexingEmbeddersearchEmbedder 一起使用。

这是一个实验性功能。使用实验性功能端点来激活它

curl \
  -X PATCH 'MEILISEARCH_URL/experimental-features/' \
  -H 'Content-Type: application/json' \
  --data-binary '{
    "compositeEmbedders": true
  }'
url

Meilisearch 查询 url 以生成查询和文档的向量嵌入。url 必须指向一个 REST 兼容的嵌入器。您还可以使用 url 处理代理,例如从代理后面访问 openAi

使用 rest 嵌入器时,此字段是强制性的。

使用 ollamaopenAi 嵌入器时,此字段是可选的。ollama URL 必须以 /api/embed/api/embeddings 结尾。

此字段与 huggingFaceuserProvided 嵌入器不兼容。

apiKey

Meilisearch 应随每次请求发送到嵌入器的身份验证令牌。

如果使用受保护的 rest 嵌入器,此字段是强制性的。

此字段对于 openAIollama 嵌入器是可选的。如果您未指定 apiKey,Meilisearch 将尝试分别从环境变量 OPENAI_API_KEYMEILI_OLLAMA_URL 中读取它。

此字段与 huggingFaceuserProvided 嵌入器不兼容。

model

您的嵌入器在生成向量时使用的模型。这些是 Meilisearch 支持的官方模型

  • openAitext-embedding-3-smalltext-embedding-3-largeopenai-text-embedding-ada-002
  • huggingFaceBAAI/bge-base-en-v1.5

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

此字段对于 Ollama 嵌入器是强制性的。

此字段对于 openAihuggingFace 是可选的。默认情况下,Meilisearch 分别使用 text-embedding-3-smallBAAI/bge-base-en-v1.5

此字段与 restuserProvided 嵌入器不兼容。

documentTemplate

documentTemplate 是一个包含 Liquid 模板的字符串。Meilisearch 会为每个文档插入模板,并将生成的文本发送到嵌入器。然后,嵌入器根据此文本生成文档向量。

您可以使用以下上下文值

  • {{doc.FIELD}}doc 代表文档本身。FIELD 必须对应于所有文档上存在的属性,该值将被输入文档中该字段的值替换。
  • {{fields}}:索引中任何文档中出现的所有 field 的列表。此列表中的每个 field 对象都具有以下属性:
    • name:字段的属性
    • value:字段的值
    • is_searchable:字段是否在可搜索属性列表中

如果文档中不存在 field,则其 valuenil

为获得最佳结果,请构建只包含高度相关数据的短模板。如果处理长字段,请考虑截断它。如果您不手动设置,documentTemplate 将包含所有可搜索和非空文档字段。这可能导致性能和相关性不佳。

此字段与 userProvided 嵌入器不兼容。

此字段是可选的,但强烈建议用于所有其他嵌入器。

documentTemplateMaxBytes

渲染文档模板的最大大小。较长的文本将被截断以适应配置的限制。

documentTemplateMaxBytes 必须是整数。它默认为 400

此字段与 userProvided 嵌入器不兼容。

此字段对所有其他嵌入器都是可选的。

dimensions

所选模型中的维度数量。如果未提供,Meilisearch 会尝试推断此值。

在大多数情况下,dimensions 应该与您所选模型的值完全相同。将 dimensions 设置为低于模型的值可能会带来性能改进,并且仅在以下 OpenAI 模型中支持

  • openAitext-embedding-3-smalltext-embedding-3-large

此字段对于 userProvided 嵌入器是强制性的。

此字段对于 openAihuggingFaceollamarest 嵌入器是可选的。

revision

使用此字段可使用模型的特定修订版本。

此字段对于 huggingFace 嵌入器是可选的。

此字段与所有其他嵌入器不兼容。

request

request 必须是 JSON 对象,其结构和数据与您必须发送到 rest 嵌入器的请求相同。

包含 Meilisearch 应发送给嵌入器的输入文本的字段必须替换为 "{{text}}"

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

  },

}

如果在一个请求中发送多个文档,请将输入字段替换为 ["{{text}}", "{{..}}"]

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

  },

}

使用 rest 嵌入器时,此字段是强制性的。

此字段与所有其他嵌入器不兼容。

response

response 必须是 JSON 对象,其结构和数据与您期望从 rest 嵌入器接收的响应相同。

包含嵌入本身的字段必须替换为 "{{embedding}}"

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

  },

}

如果单个响应包含多个嵌入,则包含嵌入本身的字段必须是一个包含两个项的数组。一个必须声明单个嵌入的位置和结构,而第二个项应为 "{{..}}"

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

  },

}

使用 rest 嵌入器时,此字段是强制性的。

此字段与所有其他嵌入器不兼容。

distribution

出于数学原因,语义搜索结果的 _rankingScore 倾向于围绕一个平均值紧密分组,该平均值取决于所使用的嵌入器和模型。这可能导致与关键词搜索结果相比,相关语义命中被低估,不相关语义命中被高估。

在配置嵌入器时使用 distribution,通过仿射变换校正语义命中的返回 _rankingScore

curl \
  -X PATCH 'MEILISEARCH_URL/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 是一个可选字段,与所有嵌入器来源兼容。它必须是一个包含两个字段的对象:

  • mean:一个介于 01 之间的数字,表示在使用 distribution 设置之前“有点相关”命中的语义分数
  • sigma:一个介于 01 之间的数字,表示“非常相关”命中与“有点相关”命中之间以及“有点相关”命中与“不相关”命中之间的 _rankingScore 的平均绝对差值。

更改 distribution 不会触发重新索引操作。

headers

headers 必须是一个 JSON 对象,其键表示要发送到嵌入器的请求中附加标头的名称,其值表示这些附加标头的值。

默认情况下,Meilisearch 会将以下标头随所有请求发送到 rest 嵌入器:

  • Authorization: Bearer EMBEDDER_API_KEY (仅当提供了 apiKey 时)
  • Content-Type: application/json

如果 headers 包含这些字段之一,则显式声明的值将优先于默认值。

使用 rest 嵌入器时,此字段是可选的。

此字段与所有其他嵌入器不兼容。

binaryQuantized

当设置为 true 时,通过用 1 位值表示每个维度来压缩向量。这会降低语义搜索结果的相关性,但会大大减小数据库大小。

此选项在处理大型 Meilisearch 项目时可能很有用。如果您的项目包含超过一百万个文档并使用超过 1400 个维度的模型,请考虑激活它。

激活 binaryQuantized 是不可逆的。一旦启用,Meilisearch 将转换所有向量并丢弃所有不适合 1 位的向量数据。恢复向量原始值的唯一方法是在新的嵌入器中重新向量化整个索引。

pooling

配置 Meilisearch 应如何将单个标记合并为单个嵌入。

pooling 必须是以下字符串之一:

  • "useModel":Meilisearch 将从模型配置中获取池化方法。新嵌入器的默认值
  • "forceMean":始终使用均值池化。Meilisearch <=v1.13 中创建的嵌入器的默认值
  • "forceCls":始终使用 CLS 池化

如有疑问,请使用 "useModel""forceMean""forceCls" 是可能对某些嵌入器和模型必要的兼容性选项。

pooling 对于来源为 huggingFace 的嵌入器是可选的。

pooling 对于所有其他嵌入器来源均无效。

indexingEmbeddersearchEmbedder 实验性

使用复合嵌入器时,配置 Meilisearch 在向量化文档和搜索查询时应使用的独立嵌入器。

indexingEmbedder 通常受益于远程提供商的更高带宽和速度,因此它可以快速向量化大批量文档。searchEmbedder 通常受益于本地处理查询的较低延迟。

这两个字段都必须是对象,并且接受与常规嵌入器相同的字段,但有以下例外:

  • indexingEmbeddersearchEmbedder 必须使用相同的模型生成嵌入
  • indexingEmbeddersearchEmbedder 必须具有相同的 dimensionpooling 方法
  • source 对于 indexingEmbeddersearchEmbedder 都是强制性的
  • 子嵌入器都不能将 source 设置为 compositeuserProvided
  • binaryQuantizeddistribution 都不是有效的子嵌入器字段,并且必须始终在主嵌入器中声明
  • documentTemplatedocumentTemplateMaxBytes 对于 searchEmbedder 是无效字段
  • 如果适用于其来源,documentTemplatedocumentTemplateMaxBytes 对于 indexingEmbedder 是强制性的

使用 composite 来源时,indexingEmbeddersearchEmbedder 是强制性的。

indexingEmbeddersearchEmbedder 与所有其他嵌入器来源不兼容。

示例

curl \
  -X PATCH 'MEILISEARCH_URL/indexes/INDEX_NAME/settings/embedders' \
  -H 'Content-Type: application/json' \
  --data-binary '{
    "default": {
      "source":  "openAi",
      "apiKey": "OPEN_AI_API_KEY",
      "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 'MEILISEARCH_URL/indexes/INDEX_NAME/settings/embedders'
响应:202 Accepted
{
  "taskUid": 1,
  "indexUid": "books",
  "status": "enqueued",
  "type": "settingsUpdate",
  "enqueuedAt": "2022-04-14T20:53:32.863107Z"
}

您可以使用返回的 taskUid 获取有关任务状态的更多详细信息。