范数
映射参数 norms
控制是否为字段计算和存储范数因子。这些因子在查询评分期间用于调整搜索结果的相关性。然而,存储 norms
会增加索引大小并消耗额外内存。
默认情况下,norms
在需要相关性评分的 text
字段上是启用的。对于不需要这些评分功能的字段,例如仅用于过滤的 keyword
字段,则禁用 norms
。
禁用字段上的 norms
以下请求创建了一个名为 products
的索引,其中 description
字段是一个 text
字段,并禁用了 norms
PUT /products
{
"mappings": {
"properties": {
"description": {
"type": "text",
"norms": false
}
}
}
}
要在现有索引中的字段上禁用 norms
,请使用以下请求
PUT /products/_mapping
{
"properties": {
"review": {
"type": "text",
"norms": false
}
}
}
在已禁用 norms
的字段上启用 norms
是不可能的,并且将导致以下错误
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Mapper for [description] conflicts with existing mapper:\n\tCannot update parameter [norms] from [false] to [true]"
}
],
"type": "illegal_argument_exception",
"reason": "Mapper for [description] conflicts with existing mapper:\n\tCannot update parameter [norms] from [false] to [true]"
},
"status": 400
}