Norms(归一化因子)
norms 映射参数控制是否为字段计算和存储归一化因子。这些因子在查询评分期间用于调整搜索结果的相关性。然而,存储 norms 会增加索引大小并消耗额外的内存。
默认情况下,text 字段上启用了 norms,因为相关性评分对这些字段很重要。不需要这些评分功能的字段,例如仅用于过滤的 keyword 字段,则配置为禁用 norms。
在字段上禁用 norms
以下请求创建一个名为 products 的索引,其中 description 字段是一个禁用了 norms 的 text 字段:
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
}