使用 /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" : {},
"chat" : {}
}
所有设置
此路由允许您一次性检索、配置或重置索引的所有设置。
获取设置
获取
/indexes/{index_uid}/settings
获取索引的设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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" : {},
"chat" : {}
}
更新设置
PATCH
/indexes/{index_uid}/settings
更新索引的设置。 将 null
传递给索引设置会将其重置为默认值。 设置路由中的更新是部分 的。这意味着请求正文中未提供的任何参数将保持不变。 如果提供的索引不存在,则会创建它。 路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
获取有关任务状态 的更多详细信息。
重置设置
删除
/indexes/{index_uid}/settings
将索引的所有设置重置为它们的默认值 。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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." ]
}
获取字典
获取
/indexes/{index_uid}/settings/dictionary
获取索引的用户定义字典。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
curl \
-X GET 'MEILISEARCH_URL/indexes/books/settings/dictionary'
响应:200 OK
更新字典
PUT
/indexes/{index_uid}/settings/dictionary
更新索引的用户定义字典。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
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
获取有关任务状态 的更多详细信息。
重置字典
删除
/indexes/{index_uid}/settings/dictionary
将索引的字典重置为默认值 []
。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
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
数组等于数据集中的所有字段。此行为由值 ["*"]
表示。 要了解有关显示属性的更多信息,请参阅我们的专门指南。 获取可显示属性
获取
/indexes/{index_uid}/settings/displayed-attributes
获取索引的显示属性。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
请求体
字符串数组。每个字符串都应是所选索引中存在的属性。 如果属性包含对象,您可以使用点表示法指定其一个或多个键,例如 "displayedAttributes": ["release_date.year"]
。
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
获取有关任务状态 的更多详细信息。
重置可显示属性
删除
/indexes/{index_uid}/settings/displayed-attributes
将索引的显示属性重置为默认值。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
获取有关任务状态 的更多详细信息。
不同属性
去重属性是一个字段,其值在返回的文档中始终是唯一的。
更新去重属性将重新索引索引中的所有文档,这可能需要一些时间。我们建议先更新索引设置,然后添加文档,因为这可以减少 RAM 消耗。
要了解有关去重属性的更多信息,请参阅我们的专门指南。
获取去重属性
获取
/indexes/{index_uid}/settings/distinct-attribute
获取索引的去重属性。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
curl \
-X GET 'MEILISEARCH_URL/indexes/shoes/settings/distinct-attribute'
响应:200 Ok
更新去重属性
PUT
/indexes/{index_uid}/settings/distinct-attribute
更新索引的去重属性字段。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
一个字符串。该字符串应是所选索引中存在的属性。 如果属性包含对象,您可以使用点表示法将其一个或多个键设置为此设置的值,例如 "distinctAttribute": "product.skuid"
。
要了解有关去重属性的更多信息,请参阅我们的专门指南。
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
获取有关任务状态 的更多详细信息。
重置去重属性
删除
/indexes/{index_uid}/settings/distinct-attribute
将索引的去重属性重置为默认值。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
) 排序
获取分面设置
获取
/indexes/{index_uid}/settings/faceting
获取索引的分面设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Dart
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
分面总共有三个值:blue
、green
和 red
。如果将 maxValuesPerFacet
设置为 2
,Meilisearch 将只在响应正文的 facetDistribution
对象中返回 blue
和 green
。
将 maxValuesPerFacet
设置为较高的值可能会对性能产生负面影响。
以下代码示例将 maxValuesPerFacet
设置为 2
,按降序计数对 genres
分面进行排序,并按升序字母数字顺序对所有其他分面进行排序
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Dart
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
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Dart
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
列表中的属性可以用作过滤器 或分面 。
更新可过滤属性将重新索引索引中的所有文档,这可能需要一些时间。为了减少 RAM 消耗,请先更新索引设置,然后添加文档。
可过滤属性对象
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
、AND
和 OR
。布尔值,默认为 true
comparison
:启用 >
、>=
、<
、<=
、TO
、EXISTS
、IS NULL
、IS EMPTY
、NOT
、AND
和 OR
。布尔值,默认为 false
计算 comparison
过滤器是一项资源密集型操作。禁用它们可能会导致更好的搜索和索引性能。equality
过滤器使用更少的资源,对性能影响有限。
可过滤属性和保留属性 使用简单的字符串语法匹配保留属性。Meilisearch 的保留字段始终以_开头 (_
),例如 _geo
和 _vector
。 如果设置为可过滤属性,保留属性将忽略 features
字段并自动激活所有搜索功能。保留字段不会被通配符 attributePatterns
匹配,例如 _*
。
获取可过滤属性
获取
/indexes/{index_uid}/settings/filterable-attributes
获取索引的可过滤属性。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
请求体
字符串数组,包含可在查询时用作过滤器的属性。当使用字符串数组格式时,所有过滤器类型都为指定属性启用。 您也可以使用对象数组: [
{
"attributePatterns": [<String>, <String>, …],
"features": {
"facetSearch": <Boolean>,
"filter": {
"equality": <Boolean>,
"comparison": <Boolean>
}
}
}
]
如果指定的字段不存在,Meilisearch 将默默忽略它。 如果属性包含对象,您可以使用点表示法将其一个或多个键设置为此设置的值:"filterableAttributes": ["release_date.year"]
或 "attributePatterns": ["release_date.year"]
。
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
curl \
-X PUT 'MEILISEARCH_URL/indexes/movies/settings/filterable-attributes' \
-H 'Content-Type: application/json' \
--data-binary '[
"genres",
"director",
{
"attributePatterns": ["*_ratings"],
"features": {
"facetSearch": false,
"filter": {
"equality": true,
"comparison": false
}
}
}
]'
响应:202 Accepted
{
"taskUid" : 1 ,
"indexUid" : "movies" ,
"status" : "enqueued" ,
"type" : "settingsUpdate" ,
"enqueuedAt" : "2021-08-11T09:25:53.000000Z"
}
您可以使用此 taskUid
获取有关任务状态 的更多详细信息。
重置可过滤属性
删除
/indexes/{index_uid}/settings/filterable-attributes
将索引的可过滤属性列表重置为默认值。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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 会自动检测文档中使用的语言。此设置允许您明确定义数据集中存在哪些语言以及在哪些字段中。 本地化属性会影响 searchableAttributes
、filterableAttributes
和 sortableAttributes
。 为单个索引配置多种语言可能会对性能产生负面影响。 locales
和 localizedAttributes
具有相同的目标:在 Meilisearch 的语言自动检测不按预期工作时,明确声明搜索中使用的语言。如果您认为 Meilisearch 因查询文本而检测到不正确的语言,请使用 locales
明确设置搜索语言。 如果您认为 Meilisearch 因文档而检测到不正确的语言,请在索引级别使用 localizedAttributes
明确设置文档语言。 要完全控制 Meilisearch 在索引时和搜索时检测语言的方式,请同时设置 locales
和 localizedAttributes
。
本地化属性对象
localizedAttributes
必须是区域设置对象数组。其默认值为 []
。 区域设置对象必须包含以下字段: 名称 类型 默认值 描述 locales
字符串数组 []
表示一个或多个 ISO-639 区域设置的字符串列表 attributePatterns
字符串数组 []
指示哪些字段对应于指定区域设置的字符串列表
locales
Meilisearch 支持以下 ISO-639-3 三字母 locales
:epo
、eng
、rus
、cmn
、spa
、por
、ita
、ben
、fra
、deu
、ukr
、kat
、ara
、hin
、jpn
、heb
、yid
、pol
、amh
、jav
、kor
、nob
、dan
、swe
、fin
、tur
、nld
、hun
、ces
、ell
、bul
、bel
、mar
、kan
、ron
、slv
、hrv
、srp
、mkd
、lit
、lav
、est
、tam
、vie
、urd
、tha
、guj
、uzb
、pan
、aze
、ind
、tel
、pes
、mal
、ori
、mya
、nep
、sin
、khm
、tuk
、aka
、zul
、sna
、afr
、lat
、slk
、cat
、tgl
、hye
。 您也可以使用支持的 locales
的 ISO-639-1 双字母等价物 。 您还可以将空数组分配给 locales
。在这种情况下,Meilisearch 将自动检测关联 attributePatterns
的语言。 attributePatterns
属性模式可以以 *
通配符开头或结尾以匹配多个字段:en_*
、*-ar
。 您还可以将 attributePatterns
设置为 *
,在这种情况下,Meilisearch 将把所有字段视为关联的区域设置。 获取本地化属性设置
获取
/indexes/{index_uid}/settings/localized-attributes
获取索引的本地化属性设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
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
JS
Python
PHP
Java
Ruby
Go
Rust
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
获取有关任务状态 的更多详细信息。
重置本地化属性设置
删除
/indexes/{index_uid}/settings/localized-attributes
将索引的本地化属性重置为它们的默认值 。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
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
优先于搜索参数,例如 limit
、offset
、hitsPerPage
和 page
。 例如,如果将 maxTotalHits
设置为 100,则无论为 offset
配置什么值,都无法访问超过 100 的搜索结果。 要了解有关使用 Meilisearch 对搜索结果进行分页的更多信息,请参阅我们的专门指南。
名称 类型 默认值 描述 maxTotalHits
整数 1000
Meilisearch 可以返回的最大搜索结果数
将 maxTotalHits
设置为高于默认值会负面影响搜索性能。将 maxTotalHits
设置为超过 20000
的值可能会导致查询完成需要数秒。
获取
/indexes/{index_uid}/settings/pagination
获取索引的分页设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Dart
curl \
-X GET 'MEILISEARCH_URL/indexes/books/settings/pagination'
响应:200 OK
PATCH
/indexes/{index_uid}/settings/pagination
部分更新索引的分页设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
{maxTotalHits: <Integer>}
名称 类型 默认值 描述 maxTotalHits
整数 1000
Meilisearch 可以返回的最大搜索结果数
将 maxTotalHits
设置为高于默认值会负面影响搜索性能。将 maxTotalHits
设置为超过 20000
的值可能会导致查询完成需要数秒。
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Dart
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
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Dart
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"
:确定同一属性中是否存在多个查询词。精度较低,但索引时间较短
获取距离精度设置
获取
/indexes/{index_uid}/settings/proximity-precision
获取索引的距离精度设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
curl \
-X GET 'MEILISEARCH_URL/indexes/books/settings/proximity-precision'
响应:200 OK
更新距离精度设置
PUT
/indexes/{index_uid}/settings/proximity-precision
更新索引的分页设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
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
获取有关任务状态 的更多详细信息。
重置距离精度设置
删除
/indexes/{index_uid}/settings/proximity-precision
将索引的距离精度设置重置为默认值。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
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 将返回错误。获取分面搜索设置
获取
/indexes/{index_uid}/settings/facet-search
获取索引的分面搜索设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Ruby
Go
Rust
curl \
-X GET 'MEILISEARCH_URL/indexes/INDEX_UID/settings/facet-search'
响应:200 OK
更新分面搜索设置
PUT
/indexes/{index_uid}/settings/facet-search
更新索引的分面搜索设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
cURL
JS
Python
PHP
Ruby
Go
Rust
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
获取有关任务状态 的更多详细信息。
重置分面搜索设置
删除
/indexes/{index_uid}/settings/facet-search
将索引的分面搜索重置为默认设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Ruby
Go
Rust
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"
:不计算前缀搜索。可能会加快索引速度,但会严重影响搜索结果的相关性
获取前缀搜索设置
获取
/indexes/{index_uid}/settings/prefix-search
获取索引的前缀搜索设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Ruby
Go
Rust
curl \
-X GET 'MEILISEARCH_URL/indexes/INDEX_UID/settings/prefix-search'
响应:200 OK
更新前缀搜索设置
PUT
/indexes/{index_uid}/settings/prefix-search
更新索引的前缀搜索设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
"indexingTime" | "disabled"
cURL
JS
Python
PHP
Ruby
Go
Rust
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
获取有关任务状态 的更多详细信息。
重置前缀搜索设置
删除
/indexes/{index_uid}/settings/prefix-search
将索引的前缀搜索重置为默认设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Ruby
Go
Rust
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"
]
获取排序规则
获取
/indexes/{index_uid}/settings/ranking-rules
获取索引的排序规则。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
请求体
一个包含排序规则的数组,按重要性排序。 要创建自定义排序规则,请给定一个属性,后跟冒号 (:
) 和 asc
表示升序或 desc
表示降序。
应用升序排序 (结果按递增值排序):attribute_name:asc
应用降序排序 (结果按递减值排序):attribute_name:desc
如果某些文档不包含自定义排序规则中定义的属性,则排序规则的应用是未定义的,搜索结果可能不会按预期排序。 确保自定义排序规则中使用的任何属性都存在于所有文档中。例如,如果将自定义排序规则设置为 desc(year)
,请确保所有文档都包含 year
属性。
要了解有关排序规则的更多信息,请参阅我们的专门指南。
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
获取有关任务状态 的更多详细信息。
重置排序规则
删除
/indexes/{index_uid}/settings/ranking-rules
将索引的排序规则重置为它们的默认值 。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
数组等于数据集中所有字段。此行为由值 ["*"]
表示。 更新可搜索属性将重新索引索引中的所有文档,这可能需要一些时间。我们建议先更新索引设置,然后添加文档,因为这可以减少 RAM 消耗。
要了解有关可搜索属性的更多信息,请参阅我们的专门指南。
获取可搜索属性
获取
/indexes/{index_uid}/settings/searchable-attributes
获取索引的可搜索属性。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
请求体
字符串数组。每个字符串都应该是所选索引中存在的属性。数组应按重要性顺序 给定:从最重要的属性到最不重要的属性。 如果属性包含对象,您可以使用点表示法将其一个或多个键设置为此设置的值:"searchableAttributes": ["release_date.year"]
。
要了解有关可搜索属性的更多信息,请参阅我们的专门指南。
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
获取有关任务状态 的更多详细信息。
重置可搜索属性
删除
/indexes/{index_uid}/settings/searchable-attributes
将索引的可搜索属性重置为默认值。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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 毫秒后中断搜索。 获取搜索截断
获取
/indexes/{index_uid}/settings/search-cutoff-ms
获取索引的搜索截断值。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
curl \
-X GET 'MEILISEARCH_URL/indexes/movies/settings/search-cutoff-ms'
响应:200 Ok
更新搜索截断
PUT
/indexes/{index_uid}/settings/search-cutoff-ms
更新索引的搜索截断值。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
表示截断值(毫秒)的单个整数。
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
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
获取有关任务状态 的更多详细信息。
重置搜索截断
删除
/indexes/{index_uid}/settings/search-cutoff-ms
将索引的搜索截断值重置为其默认值 null
。这相当于截断 1500 毫秒。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
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
设置 。获取分隔符标记
获取
/indexes/{index_uid}/settings/separator-tokens
获取索引的自定义分隔符标记列表。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
curl \
-X GET 'MEILISEARCH_URL/indexes/articles/settings/separator-tokens'
响应:200 Ok
更新分隔符标记
PUT
/indexes/{index_uid}/settings/separator-tokens
更新索引的自定义分隔符标记列表。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
字符串数组,每个字符串指示一个单词分隔符。
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
curl \
-X PUT 'MEILISEARCH_URL/indexes/articles/settings/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
获取有关任务状态 的更多详细信息。
重置分隔符标记
删除
/indexes/{index_uid}/settings/separator-tokens
将索引的自定义分隔符标记列表重置为其默认值 []
。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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 默认的单词分隔符列表 中删除标记。
获取非分隔符标记
获取
/indexes/{index_uid}/settings/non-separator-tokens
获取索引的非分隔符标记列表。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
获取有关任务状态 的更多详细信息。
重置非分隔符标记
删除
/indexes/{index_uid}/settings/non-separator-tokens
将索引的非分隔符标记列表重置为其默认值 []
。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
搜索参数 的属性。
更新可排序属性将重新索引索引中的所有文档,这可能需要一些时间。我们建议先更新索引设置,然后添加文档,因为这可以减少 RAM 消耗。
要了解有关可排序属性的更多信息,请参阅我们的专门指南。
获取可排序属性
获取
/indexes/{index_uid}/settings/sortable-attributes
获取索引的可排序属性。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
请求体
字符串数组。每个字符串都应该是所选索引中存在的属性。 如果属性包含对象,您可以使用点表示法将其一个或多个键设置为此设置的值:"sortableAttributes": ["author.surname"]
。
要了解有关可排序属性的更多信息,请参阅我们的专门指南。
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
获取有关任务状态 的更多详细信息。
重置可排序属性
删除
/indexes/{index_uid}/settings/sortable-attributes
将索引的可排序属性列表重置回其默认值。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
列表的单词将在未来的搜索查询中被忽略。
更新停用词将重新索引索引中的所有文档,这可能需要一些时间。我们建议先更新索引设置,然后添加文档,因为这可以减少 RAM 消耗。
停用词与数据集中使用的语言密切相关。例如,大多数包含英语文档的数据集会无数次出现 the
和 of
。而意大利语数据集则会受益于忽略 a
、la
或 il
等词。 GitHub 上的这个开源项目 提供了不同语言中可能的停用词列表。请注意,根据您的数据集和用例,您需要调整这些列表以获得最佳结果。
获取停用词
获取
/indexes/{index_uid}/settings/stop-words
获取索引的停用词列表。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
curl \
-X GET 'MEILISEARCH_URL/indexes/movies/settings/stop-words'
响应:200 Ok
更新停用词
PUT
/indexes/{index_uid}/settings/stop-words
更新索引的停用词列表。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
字符串数组。每个字符串都应该是一个单词。 如果停用词列表已存在,它将被覆盖(替换 )。
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
获取有关任务状态 的更多详细信息。
重置停用词
删除
/indexes/{index_uid}/settings/stop-words
将索引的停用词列表重置为默认值。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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 中,为了计算搜索结果,同义词被认为与其关联的单词相等。 要了解有关同义词的更多信息,请参阅我们的专门指南。 获取同义词
获取
/indexes/{index_uid}/settings/synonyms
获取索引的同义词列表。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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
获取有关任务状态 的更多详细信息。
重置同义词
删除
/indexes/{index_uid}/settings/synonyms
将索引的同义词列表重置为默认值。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
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 个错别字的最小单词大小;必须介于 0
和 twoTypos
之间 minWordSizeForTypos.twoTypos
整数 9
接受 2 个错别字的最小单词大小;必须介于 oneTypo
和 255
之间 disableOnWords
字符串数组 空 禁用错别字容忍度功能的单词数组 disableOnAttributes
字符串数组 空 禁用错别字容忍度功能的属性数组 disableOnNumbers
布尔值 false
是否禁用或启用数字的错别字容忍度
获取错别字容忍度设置
获取
/indexes/{index_uid}/settings/typo-tolerance
获取索引的错别字容忍度设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Dart
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 个错别字的最小单词大小;必须介于 0
和 twoTypos
之间 minWordSizeForTypos.twoTypos
整数 9
接受 2 个错别字的最小单词大小;必须介于 oneTypo
和 255
之间 disableOnWords
字符串数组 空 禁用错别字容忍度功能的单词数组 disableOnAttributes
字符串数组 空 禁用错别字容忍度功能的属性数组 disableOnNumbers
布尔值 false
是否禁用或启用数字的错别字容忍度
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Dart
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
获取有关任务状态 的更多详细信息。
重置错别字容忍度设置
删除
/indexes/{index_uid}/settings/typo-tolerance
将索引的错别字容忍度设置重置为它们的默认值 。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Dart
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
字符串 空 将从文档生成嵌入的第三方工具。必须是 openAi
、huggingFace
、ollama
、rest
或 userProvided
url
字符串 https://:11434/api/embeddings
Meilisearch 查询嵌入器时联系的 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
对象 空 描述搜索结果的自然分布。必须包含两个字段 mean
和 sigma
,每个字段包含一个介于 0
和 1
之间的数值 request
对象 空 表示 Meilisearch 向远程嵌入器发出的请求的 JSON 值 response
对象 空 表示 Meilisearch 期望从远程嵌入器接收的响应的 JSON 值 binaryQuantized
布尔值 空 一旦设置为 true
,不可逆地将所有向量维度转换为 1 位值 indexingEmbedder
对象 空 配置嵌入器以在索引期间向量化文档 searchEmbedder
对象 空 配置嵌入器以向量化搜索查询 pooling
字符串 "useModel"
Hugging Face 嵌入器的池化方法 indexingFragments
对象 空 配置索引时的多模态嵌入生成 searchFragments
对象 空 配置多模态搜索期间的数据处理
获取嵌入器设置
获取
/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
以在索引时使用一个嵌入器,在搜索时使用另一个嵌入器。必须与indexingEmbedder
和 searchEmbedder
一起使用。
这是一个实验性功能。使用实验性功能端点激活它。 curl \
-X PATCH 'MEILISEARCH_URL/experimental-features/' \
-H 'Content-Type: application/json' \
--data-binary '{
"compositeEmbedders": true
}'
url
Meilisearch 查询 url
以生成查询和文档的向量嵌入。url
必须指向与 REST 兼容的嵌入器。您也可以使用 url
处理代理,例如从代理后面定位 openAi
。 使用 rest
嵌入器时,此字段是强制性的。 使用 ollama
和 openAi
嵌入器时,此字段是可选的。ollama
URL 必须以 /api/embed
或 /api/embeddings
结尾。 此字段与 huggingFace
和 userProvided
嵌入器不兼容。 apiKey
Meilisearch 应随每个请求发送到嵌入器的身份验证令牌。 如果使用受保护的 rest
嵌入器,则此字段是强制性的。 此字段对于 openAI
和 ollama
嵌入器是可选的。如果您在使用 openAI
时未指定 apiKey
,Meilisearch 会尝试从 OPENAI_API_KEY
环境变量中读取它。 此字段与 huggingFace
和 userProvided
嵌入器不兼容。 model
您的嵌入器在生成向量时使用的模型。这些是 Meilisearch 支持的官方模型
openAi
:text-embedding-3-small
、text-embedding-3-large
、openai-text-embedding-ada-002
huggingFace
:BAAI/bge-base-en-v1.5
其他模型,例如 HuggingFace 的 BERT 模型 或 Ollama 和 REST 嵌入器提供的模型也可能与 Meilisearch 兼容。 此字段对于 Ollama
嵌入器是强制性的。 此字段对于 openAi
和 huggingFace
是可选的。默认情况下,Meilisearch 分别使用 text-embedding-3-small
和 BAAI/bge-base-en-v1.5
。 此字段与 rest
和 userProvided
嵌入器不兼容。 documentTemplate
documentTemplate
是一个包含 Liquid 模板 的字符串。Meilisearch 为每个文档插值模板并将生成的文本发送到嵌入器。嵌入器然后根据此文本生成文档向量。 您可以使用以下上下文值:
{{doc.FIELD}}
:doc
代表文档本身。FIELD
必须对应于输入文档中所有文档都存在的属性值将替换为该字段的值
{{fields}}
:索引中任何文档中出现的所有 field
的列表。此列表中的每个 field
对象都具有以下属性
name
:字段的属性
value
:字段的值
is_searchable
:字段是否在可搜索属性列表中
如果文档中不存在 field
,则其 value
为 nil
。 为了获得最佳结果,请构建只包含高度相关数据的短模板。如果处理长字段,请考虑截断它 。如果您不手动设置,documentTemplate
将包含所有可搜索且非空的文档字段。这可能会导致性能和相关性不佳。 此字段与 userProvided
嵌入器不兼容。 此字段是可选的,但强烈建议用于所有其他嵌入器。 documentTemplateMaxBytes
渲染文档模板的最大大小。较长的文本将被截断以适应配置的限制。 documentTemplateMaxBytes
必须是整数。默认值为 400
。 此字段与 userProvided
嵌入器不兼容。 此字段对于所有其他嵌入器是可选的。 dimensions
所选模型中的维度数量。如果未提供,Meilisearch 会尝试推断此值。 在大多数情况下,dimensions
应与所选模型的精确值相同。将 dimensions
设置为低于模型的值可能会导致性能改进,并且仅在以下 OpenAI 模型中受支持:
openAi
:text-embedding-3-small
、text-embedding-3-large
此字段对于 userProvided
嵌入器是强制性的。 此字段对于 openAi
、huggingFace
、ollama
和 rest
嵌入器是可选的。 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
和相关性,添加该索引观察到的 mean
和 sigma
值。 distribution
是一个可选字段,与所有嵌入器源兼容。它必须是一个包含两个字段的对象:
mean
:介于 0
和 1
之间的数字,表示在使用 distribution
设置之前“有点相关”的命中的语义分数
sigma
:介于 0
和 1
之间的数字,表示“非常相关”命中与“有点相关”命中之间以及“有点相关”命中与“不相关”命中之间 _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"
是兼容性选项,可能对某些嵌入器和模型是必需的。 对于源为 huggingFace
的嵌入器,pooling
是可选的。 对于所有其他嵌入器源,pooling
无效。 indexingEmbedder
和 searchEmbedder
实验性
使用复合嵌入器 时,配置 Meilisearch 在向量化文档和搜索查询时应使用的独立嵌入器。 indexingEmbedder
通常受益于远程提供商的更高带宽和速度,因此它可以快速向量化大量文档。searchEmbedder
通常受益于本地处理查询的更低延迟。 这两个字段都必须是对象,并接受与常规嵌入器相同的字段,但以下例外:
indexingEmbedder
和 searchEmbedder
必须使用相同的模型生成嵌入
indexingEmbedder
和 searchEmbedder
必须具有相同的 dimension
和 pooling
方法
source
对于 indexingEmbedder
和 searchEmbedder
都是强制性的
任何子嵌入器都不能将 source
设置为 composite
或 userProvided
binaryQuantized
和 distribution
都不是有效的子嵌入器字段,并且必须始终在主嵌入器中声明
documentTemplate
和 documentTemplateMaxBytes
对于 searchEmbedder
是无效字段
如果适用于其源,则 documentTemplate
和 documentTemplateMaxBytes
对于 indexingEmbedder
是强制性的
indexingEmbedder
和 searchEmbedder
在使用 composite
源时是强制性的。 indexingEmbedder
和 searchEmbedder
与所有其他嵌入器源不兼容。indexingFragments
实验性
这是一项实验性功能。请使用 Meilisearch Cloud UI 或实验性功能端点来激活它 curl \
-X PATCH 'MEILISEARCH_URL/experimental-features/' \
-H 'Content-Type: application/json' \
--data-binary '{
"multimodal": true
}'
indexingFragments
指定文档中哪些字段应用于生成多模态嵌入。它必须是一个具有以下结构的对象
"FRAGMENT_NAME" : {
"value" : {
…
}
}
FRAGMENT_NAME
可以是任何有效字符串。它必须包含一个字段 value
。然后,value
必须遵循您选择的模型规范。 例如,对于 VoyageAI 的多模态嵌入路由 ,value
必须是包含 content
字段的对象。content
本身必须包含一个带有 type
字段的对象数组。根据 type
的值,您必须包含 text
、image_url
或 image_base64
: {
"VOYAGE_FRAGMENT_NAME_A" : {
"value" : {
"content" : [
{
"type" : "text" ,
"text" : "A document called {{doc.title}} that can be described as {{doc.description}}"
}
]
}
},
"VOYAGE_FRAGMENT_NAME_B" : {
"value" : {
"content" : [
{
"type" : "image_url" ,
"image_url" : "{{doc.image_url}}"
}
]
}
},
}
使用 Liquid 模板将文档数据插入到片段字段中,其中 doc
允许您访问文档中的所有字段。 使用 rest
源时,indexingFragments
是可选的。 indexingFragments
与所有其他嵌入器源不兼容。 在使用 indexingFragments
时,您必须在 searchFragments
中指定至少一个有效片段。 searchFragments
实验性
这是一项实验性功能。请使用 Meilisearch Cloud UI 或实验性功能端点来激活它 curl \
-X PATCH 'MEILISEARCH_URL/experimental-features/' \
-H 'Content-Type: application/json' \
--data-binary '{
"multimodal": true
}'
searchFragments
指示 Meilisearch 如何解析查询的media
搜索参数 中存在的字段。它必须是一个与indexingFragments
对象结构相同的对象
"FRAGMENT_NAME" : {
"value" : {
…
}
}
与 indexingFragments
一样,value
的内容应遵循模型的规范。 使用 Liquid 模板将搜索查询数据插入到片段字段中,其中 media
允许您访问查询接收到的所有多模态数据: "SEARCH_FRAGMENT_A" : {
"value" : {
"content" : [
{
"type" : "image_base64" ,
"image_base64" : "data:{{media.image.mime}};base64,{{media.image.data}}"
}
]
}
},
使用 rest
源时,searchFragments
是可选的。 searchFragments
与所有其他嵌入器源不兼容。 在使用 searchFragments
时,您必须在 indexingFragments
中指定至少一个有效片段。
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
获取有关任务状态 的更多详细信息。
重置嵌入器设置
删除
/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
获取有关任务状态 的更多详细信息。
聊天 实验性
这是一项实验性功能。请使用 Meilisearch Cloud UI 或实验性功能端点来激活它 curl \
-X PATCH 'https://:7700/experimental-features/' \
-H 'Authorization: Bearer MEILISEARCH_API_KEY' \
-H 'Content-Type: application/json' \
--data-binary '{
"chatCompletions": true
}'
聊天设置允许您配置索引如何与 Meilisearch 的会话搜索功能集成。
聊天对象
{
"description" : "A comprehensive movie database containing titles, overviews, genres, and release dates to help users find movies" ,
"documentTemplate" : "{% for field in fields %}{% if field.is_searchable and field.value != nil %}{{ field.name }}: {{ field.value }} \n {% endif %}{% endfor %}" ,
"documentTemplateMaxBytes" : 400 ,
"searchParameters" : {
"hybrid" : { "embedder" : "my-embedder" },
"limit" : 20
}
}
聊天对象可以包含以下字段
名称 类型 默认值 描述 description
字符串 空 索引的描述。帮助 LLM 决定在生成答案时使用哪个索引 documentTemplate
字符串 {% for field in fields %} {% if field.is_searchable and not field.value == nil %}{{ field.name }}: {{ field.value }} {% endif %} {% endfor %}
定义 Meilisearch 发送给 LLM 的数据的模板 documentTemplateMaxBytes
整数 400 渲染文档模板允许的最大大小 searchParameters
对象 空 LLM 执行搜索请求时要使用的搜索参数
搜索参数对象
必须是以下搜索参数 之一
hybrid
limit
sort
distinct
matchingStrategy
attributesToSearchOn
rankingScoreThreshold
获取索引聊天设置
获取
/indexes/{index_uid}/settings/chat
获取为索引配置的索引聊天设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
curl \
-X GET 'https://:7700/indexes/movies/settings/chat' \
-H 'Authorization: Bearer MEILISEARCH_KEY'
响应:200 OK
{
"description" : "" ,
"documentTemplate" : "{% for field in fields %} {% if field.is_searchable and not field.value == nil %}{{ field.name }}: {{ field.value }} {% endif %} {% endfor %}" ,
"documentTemplateMaxBytes" : 400 ,
"searchParameters" : {}
}
更新索引聊天设置
PUT
/indexes/{index_uid}/settings/chat
部分更新索引的聊天设置。
路径参数
名称 类型 描述 index_uid
*字符串 请求索引的 uid
请求体
{
"description" : <String> ,
"documentTemplate" : <String> ,
"documentTemplateMaxBytes" : <Integer> ,
"searchParameters" : {
"hybrid" : <Object> ,
"limit" : <Integer> ,
"sort" : [ <String> , <String> , … ],
"distinct" : <String> ,
"matchingStrategy" : <String> ,
"attributesToSearchOn" : [ <String> , <String> , … ],
"rankingScoreThreshold" : <Float> ,
}
}
curl \
-X PATCH 'https://:7700/indexes/movies/settings/chat' \
-H 'Authorization: Bearer MEILISEARCH_KEY' \
-H 'Content-Type: application/json' \
--data-binary '{
"description": "A comprehensive movie database containing titles, descriptions, genres, and release dates to help users find movies",
"documentTemplate": "Title: {{ title }}\nDescription: {{ overview }}\nGenres: {{ genres }}\n",
"documentTemplateMaxBytes": 400,
"searchParameters": {
"limit": 20
}
}'
响应:202 Accepted
{
"taskUid" : 1 ,
"indexUid" : "movies" ,
"status" : "enqueued" ,
"type" : "settingsUpdate" ,
"enqueuedAt" : "2024-05-11T09:33:12.691402Z"
}
您可以使用返回的 taskUid
获取有关任务状态 的更多详细信息。