# Popularity Sort and Rethinkdb

**URL:** <https://discuss.elastic.co/t/popularity-sort-and-rethinkdb/39362>\
**Category:** Elasticsearch\
**Created:** [January 15, 2016, 10:21pm UTC](https://discuss.elastic.co/t/popularity-sort-and-rethinkdb/39362 "2016-01-15T22:21:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wdav](https://avatars.discourse-cdn.com/v4/letter/w/76d3ee/32.png) [@wdav](https://discuss.elastic.co/u/wdav)\
**Post date:** [January 15, 2016, 10:21pm UTC](https://discuss.elastic.co/t/popularity-sort-and-rethinkdb/39362/1 "2016-01-15T22:21:13Z")

</div>

Goal: sort items by popularity using a unit of time (1 hour, 24 hours, week, etc.)

I'm using rethinkdb for storing the likes. To grab the likes of all the users in the past 24 hours, I do something like this:

```
r.table('users')('likes').between(/*24 hours*/).run()

```

I then count the times an item appears and put the id of the item in a dictionary along with its like count  
I then have to query for the liked items to get all of their information needed for display to a user.

If I do all of this every 5 minutes, I should have the desired results.

Is there a better way to do this with elasticsearch?  
Is it easy for me to use elasticsearch with rethinkdb or to move my existing data over to elasticsearch and begin storing it there?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [January 16, 2016, 12:00am UTC](https://discuss.elastic.co/t/popularity-sort-and-rethinkdb/39362/2 "2016-01-16T00:00:52Z")

</div>

You probably want a date range agg with another on the users field (terms sub-agg).  
Honestly though, it won't be as easy as that single line.

> [@wdav](#):
>
> Is it easy for me to use elasticsearch with rethinkdb or to move my existing data over to elasticsearch and begin storing it there?

We can't answer that, only you can.

---

<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:** [July 5, 2017, 11:23pm UTC](https://discuss.elastic.co/t/popularity-sort-and-rethinkdb/39362/3 "2017-07-05T23:23:55Z")

</div>


