# Explain the function score of match\_phrase\_prefix

**URL:** <https://discuss.elastic.co/t/explain-the-function-score-of-match-phrase-prefix/283348>\
**Category:** Elasticsearch\
**Created:** [September 4, 2021, 4:21pm UTC](https://discuss.elastic.co/t/explain-the-function-score-of-match-phrase-prefix/283348 "2021-09-04T16:21:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LazyMonster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lazymonster/32/94166_2.png) [@LazyMonster](https://discuss.elastic.co/u/LazyMonster)\
**Post date:** [September 4, 2021, 4:21pm UTC](https://discuss.elastic.co/t/explain-the-function-score-of-match-phrase-prefix/283348/1 "2021-09-04T16:21:56Z")

</div>

I have a problem with match\_phrase\_prefix query. Let me elaborate my case:  
I use a script similarity like this:

```auto
{
  "similarity": {
      "custom_tfidf": {
        "type": "scripted",
        "script": {
          "source": "double tf = doc.freq > 0 ? 1 : 0; return query.boost * tf;"
        }
      }
    }
}

```

When the `match_phrase_prefix` is applied on a query `this is a query `, the score for some result will be like this:

- this is a query in the head. \_score = 7
- this is a query in the head with additional text. \_score = 7
- do you know this is a query. \_score = 6

I have tried using `explain` in the elasticsearch query but the result was not clear why \_score is 7 or 6. For 7 it is sum of seven 1 numbers.  
I am also try to find in elasticsearch source code [https://github.com/elastic/elasticsearch](https://github.com/elastic/elasticsearch) here but cannot find where is the code for calculating the \_score above.  
Could you please help me to make clear the function to calculate the above score? I'm so appreciative if you can help me to specify the function in the source code above.

---

<div class="post-metadata">

**Author:** ![LazyMonster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lazymonster/32/94166_2.png) [@LazyMonster](https://discuss.elastic.co/u/LazyMonster)\
**Post date:** [September 21, 2021, 2:37pm UTC](https://discuss.elastic.co/t/explain-the-function-score-of-match-phrase-prefix/283348/2 "2021-09-21T14:37:59Z")

</div>

Hi there. Please can help me for this topic.

---

<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:** [October 19, 2021, 2:38pm UTC](https://discuss.elastic.co/t/explain-the-function-score-of-match-phrase-prefix/283348/3 "2021-10-19T14:38:41Z")

</div>

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