# How can I sort results by popular item on ElasticSearch

**URL:** <https://discuss.elastic.co/t/how-can-i-sort-results-by-popular-item-on-elasticsearch/124683>\
**Category:** Elasticsearch\
**Created:** [March 20, 2018, 5:20am UTC](https://discuss.elastic.co/t/how-can-i-sort-results-by-popular-item-on-elasticsearch/124683 "2018-03-20T05:20:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nutanek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nutanek1/32/29009_2.png) [@nutanek1](https://discuss.elastic.co/u/nutanek1)\
**Post date:** [March 20, 2018, 5:20am UTC](https://discuss.elastic.co/t/how-can-i-sort-results-by-popular-item-on-elasticsearch/124683/1 "2018-03-20T05:20:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 17, 2018, 5:20am UTC](https://discuss.elastic.co/t/how-can-i-sort-results-by-popular-item-on-elasticsearch/124683/2 "2018-04-17T05:20:36Z")

</div>

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