2

I have a field in the document that is a ranking: where the lower the value, the higher the score it should have. Being first is best, but being last is the worst. So a ranking of 1 is better than 1 million.

So far I've been able to boost on the field value itself with score_query and field_value_factor, but it gives the docs with ranks of higher numbers the higher boosts.

"field_value_factor": {
  "field": "rank",
  "factor": 1.2,
  "modifier": "sqrt",
  "missing": 1
}

Should I be using a different modifier? Or am I going about this completely wrong? Also, I don't want to sort on it alone since I have other factors influencing the _score.

Dan Mašek
  • 17,852
  • 6
  • 57
  • 85
JayNCoke
  • 1,091
  • 2
  • 11
  • 17
  • There doesn't seem to be anything in this question related to [Boost c++ libraries](http://stackoverflow.com/tags/boost/info) -- please don't misuse tags. (As someone who's been frequenting this site for 7+ years, you ought to know this by now) – Dan Mašek Feb 17 '17 at 20:59
  • Whoops, got tag happy there. Sorry about that. Been a while since I've asked a question though. Thanks for catching that, @DanMašek – JayNCoke Feb 17 '17 at 21:00
  • No worries, it can happen :) It was actually kinda funny seeing that on something tagged with "relevance" :D – Dan Mašek Feb 17 '17 at 21:01

1 Answers1

2

You actually need to take a modifier function that reciprocates the rank value, i.e. 1 / rank, so that the higher the rank is, the lower the value will be will and rank = 1 will get a score of 1. The only one that does it is reciprocal

"field_value_factor": {
  "field": "rank",
  "factor": 1.2,
  "modifier": "reciprocal",
  "missing": 1
}
Val
  • 207,596
  • 13
  • 358
  • 360