Boosting the relevance score based on the unique keyword found


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

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, 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.

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.

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. Otherwise this should just work.