# Why field length during calculating BM25 score is approximate

**URL:** <https://discuss.elastic.co/t/why-field-length-during-calculating-bm25-score-is-approximate/360832>\
**Category:** Elastic Search\
**Created:** [June 5, 2024, 7:31am UTC](https://discuss.elastic.co/t/why-field-length-during-calculating-bm25-score-is-approximate/360832 "2024-06-05T07:31:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zheng\_fang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zheng_fang/32/135043_2.png) [@zheng\_fang](https://discuss.elastic.co/u/zheng_fang)\
**Post date:** [June 5, 2024, 7:31am UTC](https://discuss.elastic.co/t/why-field-length-during-calculating-bm25-score-is-approximate/360832/1 "2024-06-05T07:31:45Z")

</div>

I use explain api to see the BM25 calculation details. I found in the tf calculation detail, the dl (field length) is not correct. the following json is what i got from explain api.

```auto
{
    "value": 0.4435187,
    "description": "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
    "details": [
        {
            "value": 1.0,
            "description": "freq, occurrences of term within document",
            "details": []
        },
        {
            "value": 1.2,
            "description": "k1, term saturation parameter",
            "details": []
        },
        {
            "value": 0.75,
            "description": "b, length normalization parameter",
            "details": []
        },
        {
            "value": 128.0,
            "description": "dl, length of field (approximate)",
            "details": []
        },
        {
            "value": 120.666664,
            "description": "avgdl, average length of field",
            "details": []
        }
    ]
}

```

we can see \<"description": "dl, length of field (approximate)",\> I want to know why the dl is approximate.

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [June 5, 2024, 10:04am UTC](https://discuss.elastic.co/t/why-field-length-during-calculating-bm25-score-is-approximate/360832/2 "2024-06-05T10:04:07Z")

</div>

Field length is a number of terms in the current field of the current document.

For example:  
if a doc1 has a field `field1` with a value "foo foo bar", its field length will be 3.  
if a doc2 has a field `field1` with a value "foo foo foo bar bar", its field length will be 5.

Is the question why is it approximate?

---

<div class="post-metadata">

**Author:** ![zheng\_fang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zheng_fang/32/135043_2.png) [@zheng\_fang](https://discuss.elastic.co/u/zheng_fang)\
**Post date:** [June 5, 2024, 11:36am UTC](https://discuss.elastic.co/t/why-field-length-during-calculating-bm25-score-is-approximate/360832/4 "2024-06-05T11:36:04Z")

</div>

Yes, I found the field length is not correct in explain api response:

```auto
{
    "value": 128.0,
    "description": "dl, length of field (approximate)",
    "details": []
}

```

the real value is 131.

---

<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:** [July 3, 2024, 11:36am UTC](https://discuss.elastic.co/t/why-field-length-during-calculating-bm25-score-is-approximate/360832/5 "2024-07-03T11:36:57Z")

</div>

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