# How can we alter the score field for specific documents depending on a particular condition

**URL:** <https://discuss.elastic.co/t/how-can-we-alter-the-score-field-for-specific-documents-depending-on-a-particular-condition/61296>\
**Category:** Elasticsearch\
**Created:** [September 22, 2016, 5:10pm UTC](https://discuss.elastic.co/t/how-can-we-alter-the-score-field-for-specific-documents-depending-on-a-particular-condition/61296 "2016-09-22T17:10:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashit\_pupu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashit_pupu/32/101113_2.png) [@ashit\_pupu](https://discuss.elastic.co/u/ashit_pupu)\
**Post date:** [September 22, 2016, 5:10pm UTC](https://discuss.elastic.co/t/how-can-we-alter-the-score-field-for-specific-documents-depending-on-a-particular-condition/61296/1 "2016-09-22T17:10:39Z")

</div>

Hi there,

I am working on a current scenario where there is a need to boost few documents in case of there is a particular text search.  
The scenario is, I have a set of documents where I have to do the term query based on a particular keyword , but the catch here is. Let's say we search for a keyword **test** it will fetch 100 records but the requirement says that few docs should come as top result, irrespective of there weightage and other criteria. How can we achieve this is Elasticsearch, any suggestion and ideas are most welcome.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [September 22, 2016, 5:24pm UTC](https://discuss.elastic.co/t/how-can-we-alter-the-score-field-for-specific-documents-depending-on-a-particular-condition/61296/2 "2016-09-22T17:24:30Z")

</div>

Have a look at [function\_score](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html). The simplest thing is to add a big score to the docs that you want at the top. You might want to squash the scores of all documents that don't match the query as well to make sure they don't get to the top.

---

<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 5, 2017, 10:18pm UTC](https://discuss.elastic.co/t/how-can-we-alter-the-score-field-for-specific-documents-depending-on-a-particular-condition/61296/3 "2017-07-05T22:18:02Z")

</div>


