# How to modify scores of documents based on partial and exact match

**URL:** <https://discuss.elastic.co/t/how-to-modify-scores-of-documents-based-on-partial-and-exact-match/315010>\
**Category:** Elasticsearch\
**Created:** [September 23, 2022, 11:13am UTC](https://discuss.elastic.co/t/how-to-modify-scores-of-documents-based-on-partial-and-exact-match/315010 "2022-09-23T11:13:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Binish\_Shams](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/binish_shams/32/111107_2.png) [@Binish\_Shams](https://discuss.elastic.co/u/Binish_Shams)\
**Post date:** [September 23, 2022, 11:13am UTC](https://discuss.elastic.co/t/how-to-modify-scores-of-documents-based-on-partial-and-exact-match/315010/1 "2022-09-23T11:13:07Z")

</div>

Hello I am finding a solution to achieve a scenario where an index having suppose 10 records each record having last name, first name and phone number etc fields and I want to do partial match and exact match for these fields and also modify the scores of the documents according to how much they match with the given value of these fields. For example, what ever value we give for firstname the documents having partial matching will have less score, documents having exact matching will have more score and two records having exact match will have same score. How can I achieve that ?  
Right Now I figured out this process

1. In order to do partial match I am going ahead I am using query string. however, tried with other queries as well such as wildcard as well but I think it does not work with text/string values
2. To modify the score of each record according to the query I considered 2 solutions
3. function\_score function
4. script\_score function
5. I am working with script\_score function now
6. Inside script\_score I am using randomScore() function with values passed as 100
7. To calculate percentage for every search result we get a max score value
8. I will be using this formula to calculate the percentages for each document  
percenatge = (score of every record/max score)\*100  
After all this I am not able to achieve desired scores for each document.

---

<div class="post-metadata">

**Author:** ![Binish\_Shams](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/binish_shams/32/111107_2.png) [@Binish\_Shams](https://discuss.elastic.co/u/Binish_Shams)\
**Post date:** [September 26, 2022, 10:22am UTC](https://discuss.elastic.co/t/how-to-modify-scores-of-documents-based-on-partial-and-exact-match/315010/2 "2022-09-26T10:22:01Z")

</div>

I am using this query for achieving above functionality

```auto
  GET customers-rcn/_search
   {
  "query": {
    "script_score": {
      "query": {
        "query_string": {
            "query": "*mol*",
              "fields": ["lastName^1.0"]
            }
          },
      "script" : {
    "source" : "randomScore(100)"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Binish\_Shams](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/binish_shams/32/111107_2.png) [@Binish\_Shams](https://discuss.elastic.co/u/Binish_Shams)\
**Post date:** [September 27, 2022, 12:11pm UTC](https://discuss.elastic.co/t/how-to-modify-scores-of-documents-based-on-partial-and-exact-match/315010/3 "2022-09-27T12:11:08Z")

</div>

Please can someone tell me the solution?

---

<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 25, 2022, 12:11pm UTC](https://discuss.elastic.co/t/how-to-modify-scores-of-documents-based-on-partial-and-exact-match/315010/4 "2022-10-25T12:11:35Z")

</div>

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