Stremovskyy
Stremovskyy

Reputation: 502

Elasticsearch - higher scoring if higher frequency search times

Suppose I have 3 Documents: A, B, C All terms are very similar, and internal score is pretty identical And people searching B more frequently than A and C, but C more frequently than A. Can I get score to order like B, C, A ?

Upvotes: 0

Views: 54

Answers (1)

apt-get_install_skill
apt-get_install_skill

Reputation: 2908

In the use case you described, you can not change the behaviour of scoring/relevancy computation. There is the possibility of boosting when using e.g. match query to affect scoring when searching for values. But that wouldn't be appropriate since you only want to sort the documents.

So the information about the search frequency has to be a part of the documents themselves, meaning it has to be an own field. Then you can simply add a sort clause like the following

{
  "query": {
     // your awesome query...
  },
  "sort": [
     {
       "search_frequency": {
         "order": "desc"
       }
     },
     "_score"
  ]
}

The challenge in this solution would be to keep the value of the field search_frequency up to date. You can do that via the Update API.

Upvotes: 1

Related Questions