# BM25 how to scoring ignore idf or set scope for total number of documents with search field

**URL:** https://discuss.elastic.co/t/bm25-how-to-scoring-ignore-idf-or-set-scope-for-total-number-of-documents-with-search-field/293104
**Category:** Elasticsearch
**Created:** [December 29, 2021, 11:03am UTC](https://discuss.elastic.co/t/bm25-how-to-scoring-ignore-idf-or-set-scope-for-total-number-of-documents-with-search-field/293104 "2021-12-29T11:03:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![wlc015f](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wlc015f/32/99632_2.png) [@wlc015f](https://discuss.elastic.co/u/wlc015f)
#### Post date: [December 29, 2021, 11:03am UTC](https://discuss.elastic.co/t/bm25-how-to-scoring-ignore-idf-or-set-scope-for-total-number-of-documents-with-search-field/293104/1 "2021-12-29T11:03:34Z")

</div>

```auto
elasticsearch version 7.16.2

index settings :
    "similarity" : {
      "default" : {
          "type" : "BM25",
          "b" : "0.75",
          "k1" : "1.2"
      }
   }

```

```auto
Data example: 

{
  "application" : 110,
  "type" : "page",
  "name" : "需要创建知识库",
  "pilot_id" : "61652c90365fc21e26cd48d0",
  "created_by" : "b03f9904e7e343dda4b79ab85a050ee1",
  "created_at" : 1637312289,
  "updated_at" : 1637312295,
  "updated_by" : "b03f9904e7e343dda4b79ab85a050ee1",
  "is_deleted" : 0,
  "is_archived" : 0,
  "addition" : {
    "published_by" : "b03f9904e7e343dda4b79ab85a050ee1",
    "published_at" : 1637312295,
    "content" : "测试",
    "participants" : []
  }
 }

```

```auto
DSL 

{
  "explain": true,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    },
    {
      "updated_at": {
        "order": "desc",
        "unmapped_type": "long"
      }
    }
  ],
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "application": 110
              }
            },
            {
              "terms": {
                "type": [
                  "page"
                ]
              }
            },
            {
              "term": {
                "is_deleted": 0
              }
            }
          ]
        }
      },
      "should": [
        {
          "multi_match": {
            "query": "创建知识",
            "fields": [
              "name",
              "addition.content"
            ],
            "type": "best_fields",
            "tie_breaker": 0.3
          }
        }
      ]
    }
  }
}

```

search explain compare is here [https://editor.mergely.com/PamGkwBm/](https://editor.mergely.com/PamGkwBm/)

```auto
score = boost * idf * tf

  idf = log(1 + (N - n + 0.5) / (n + 0.5)) 
    n, number of documents containing term
    N, total number of documents with field

  tf = freq / (freq + k1 * (1 - b + b * dl / avgdl))
    freq, occurrences of term within document
    k1, term saturation parameter 
    b, length normalization parameter 
    dl, length of field
    avgdl, average length of field

```

```auto
data stats:
data with `name` field count is 437273
data with `addition.content` field count is 11397

```

i need to search one keyword in two fields `name` and `addition.content`, some doc's `addition.content` is empty , through the compare and the score calculation formula, `N` is the biggest influence factor, how can i ignore the total number of documents, or is there some way to specify the scope of `N` ?

thanks

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [January 26, 2022, 11:04am UTC](https://discuss.elastic.co/t/bm25-how-to-scoring-ignore-idf-or-set-scope-for-total-number-of-documents-with-search-field/293104/2 "2022-01-26T11:04:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
