【Elasticsearch】BM25的discount_overlaps参数
`discount_overlaps` 是 Elasticsearch/Lucene 相似度模型(Similarity)里的一个布尔参数,用来决定:
> 在计算文档长度归一化因子(norm)时,是否忽略“重叠 token”(即位置增量 positionIncrement=0 的 token)。
---
✅ 默认值与含义
参数值 含义
`true`(默认) 重叠 token 不计入文档长度,不影响 norm
`false` 重叠 token 会计入文档长度,参与 norm 计算
---
✅ 使用场景举例
- 如果你使用了 同义词过滤器(synonym filter),多个同义词可能会落在 同一位置,这些 token 的 `positionIncrement=0`。
- 默认 `discount_overlaps=true` 会让这些 token 不影响文档长度,从而避免重复同义词“人为”拉长文档。
- 如果你希望这些 token 也参与长度计算,可设为 `false`。
---
✅ 配置示例(BM25)
```json
PUT /my_index
{
"settings": {
"index": {
"similarity": {
"my_bm25": {
"type": "BM25",
"k1": 1.2,
"b": 0.75,
"discount_overlaps": false
}
}
}
},
"mappings": {
"properties": {
"title": {
"type": "text",
"similarity": "my_bm25"
}
}
}
}
```