`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"
? ? ? }
? ? }
? }
}
```