# How to modify terms query scoring function

**URL:** <https://discuss.elastic.co/t/how-to-modify-terms-query-scoring-function/197416>\
**Category:** Elasticsearch\
**Created:** [August 29, 2019, 8:20pm UTC](https://discuss.elastic.co/t/how-to-modify-terms-query-scoring-function/197416 "2019-08-29T20:20:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veshnu\_Ramakrishnan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/veshnu_ramakrishnan/32/53329_2.png) [@Veshnu\_Ramakrishnan](https://discuss.elastic.co/u/Veshnu_Ramakrishnan)\
**Post date:** [August 29, 2019, 8:20pm UTC](https://discuss.elastic.co/t/how-to-modify-terms-query-scoring-function/197416/1 "2019-08-29T20:20:43Z")

</div>

My document is given bellow:

> {  
> "display\_name": "WarriorWorld234",  
> "friends": [  
> "b2ad7a2c-cdf4-4d69-84df-696df7091bcd",  
> "da64898a-d2cb-4f58-b636-a15c05bbad44"  
> ]  
> }

My query is

> "terms": {  
> "friends": [  
> "66e77329-c1d8-4504-a3c3-fcda6a270a5e"  
> ]  
> }

But irrespective of how many ever keywords matched, The score is just a constant score. I want the score to be number of keywords found in the document. How do I achieve it?  
I also want to return the number of keywords matched as part of result.  
I don't want to use explain.  
I don't want to use highlights either. This will increase the size of the results. I just want the count and not the list of matches per document.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [August 29, 2019, 9:02pm UTC](https://discuss.elastic.co/t/how-to-modify-terms-query-scoring-function/197416/2 "2019-08-29T21:02:46Z")

</div>

Use a ‘term’ (singular) query.  
If you have multiple search terms put multiple term queriy clauses in a bool query’s “should” array.

---

<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:** [September 26, 2019, 9:02pm UTC](https://discuss.elastic.co/t/how-to-modify-terms-query-scoring-function/197416/3 "2019-09-26T21:02:47Z")

</div>

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