JayNCoke
JayNCoke

Reputation: 1091

In Elasticsearch, how do you boost a score by the value of a ranking (1st, 2nd, 3rd...) field?

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.

Upvotes: 2

Views: 974

Answers (1)

Val
Val

Reputation: 217304

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
}

Upvotes: 2

Related Questions