How can I sort results by popular item on ElasticSearch

0
down vote
favorite
I ran into some problem about sorting. If I want to do sorting on ElasticSearch by frequently found results, how can I do it?

For example, I have 3 docs that contain keyword like this.

{
    title: "red shirt"
},
{
    title: "blue shirt"
},
{
    title: "green shirt"
}

and I usually find "green shirt" so when I do sorting by popular items then it will shows "green shirt" on top of results.

Now, I have an idea for solving is when I've found the results I will use "update_by_query" to update "popular_score" like below

"script": {
    "source": "ctx._source.popular_score++",
    "lang": "painless"
  },

This means I must call API to update popular_score every search requests, but I don't think it's good!

What should I do about this,

Thanks for your helps.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.