Getting a small random sample of getAll() for a specific index value that has 100k entries?

10 views
Skip to first unread message

Geoff Plitt

unread,
Feb 13, 2019, 4:52:15 PM2/13/19
to reth...@googlegroups.com
Our app uses ReThinkDB and stores posts with a topic key, and sometimes there are hundreds of thousands of posts on a topic.

We'd like quick access to a small random sample of posts for a topic; So we're doing r.table('posts').getAll('avengers_infinity_war', {index:'topic'}).sample(5) .

The problem is, this approach seems to take a while, due to gathering the entire set of entries (thousands) before choosing a random 5.

Is there a smarter way to sample the index-space for a particular index value?

Maybe what I need to do is introduce a composite key which is a concatenation of the topic followed by a fixed-length-random-digits, and then do a between query with random from/to params?

Any other ideas?
Reply all
Reply to author
Forward
0 new messages