# Boosting the relevance score based on the unique keyword found

**URL:** <https://discuss.elastic.co/t/boosting-the-relevance-score-based-on-the-unique-keyword-found/62177>\
**Category:** Elasticsearch\
**Created:** [October 4, 2016, 2:57pm UTC](https://discuss.elastic.co/t/boosting-the-relevance-score-based-on-the-unique-keyword-found/62177 "2016-10-04T14:57:40Z")\
**Posts on this page:** 5\
**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:** [October 4, 2016, 2:57pm UTC](https://discuss.elastic.co/t/boosting-the-relevance-score-based-on-the-unique-keyword-found/62177/1 "2016-10-04T14:57:40Z")

</div>

Hi

I am in a scenario where I need to give more relevance to the document in Index if it has a unique keyword. Let me provide a scenario.  
Let's say I need to search for a term **znkdref unsuccessfull** so the result will have contents which have **znkdref** or **unsuccessfull** or **znkdref unsuccessfull** but here I want that the contents which are having **znkdref unsuccessfull** should have highest relevance and then **znkdref** should have less relevance and then **unsuccessfull** should have least relevance.

Is there a way to achieve this ?? I would be glad to get any help

---

<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:** [October 4, 2016, 3:27pm UTC](https://discuss.elastic.co/t/boosting-the-relevance-score-based-on-the-unique-keyword-found/62177/2 "2016-10-04T15:27:28Z")

</div>

Two things:

1. Apply a higher weight to the `znkdref` term in the query. How you do this is dependent on the queries you are using but you can always use two match queries, one with a higher boost for `znkdref`. Have a look [here](https://www.elastic.co/guide/en/elasticsearch/guide/current/query-time-boosting.html), but you'll want to dig through the query dsl docucumentation for the query you use to figure out exactly how to set it up.
2. You can also do a phrase query to get when you have those two terms near each other an in the right order. This is much more expensive than a `match` query but if you add them both to a `bool` query's `should` section you can get great results. You can move the phrase query to a `rescore` if you find it to be too slow.

---

<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:** [October 4, 2016, 3:40pm UTC](https://discuss.elastic.co/t/boosting-the-relevance-score-based-on-the-unique-keyword-found/62177/3 "2016-10-04T15:40:42Z")

</div>

Hi Nik,

Thanks for the response, the issue with first approach is we don't know which terms we will be getting. We have to determine that which term is unique in run time only. What I have stated is just an example we will have various other cases as such.

---

<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:** [October 4, 2016, 5:12pm UTC](https://discuss.elastic.co/t/boosting-the-relevance-score-based-on-the-unique-keyword-found/62177/4 "2016-10-04T17:12:25Z")

</div>

Rarer terms are already worth more. That is how the scoring model works by default. You can make it more accurate by [changing the search type](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-type.html#dfs-query-then-fetch). Otherwise this _should_ just work.

---

<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:15pm UTC](https://discuss.elastic.co/t/boosting-the-relevance-score-based-on-the-unique-keyword-found/62177/5 "2017-07-05T22:15:02Z")

</div>


