Best approach to retrieve ordered counter from Cassandra

Viewed 99

I'm using Cassandra to save word and its frequency.

The table schema will be like

CREATE TABLE keywords_rate (
    some_id int,
    keyword Text,
    frequency counter,
    PRIMARY KEY (some_id, keyword)
);

The problem is, I have millions of records and I need to get the top 100 keywords for each some_id

but to do this, I need to get all keywords for given some_id and sort them on the backend (python), then get the first 100 records. which is a very costly operation for me.

So my question is: can I sort the counter inside Cassandra? and if not, what is the best approach to this scenario?

Thanks.

1 Answers

If you're using Cassandra for just this use case, and if you don't have a lot of investment on it already, my best advice is... Choose a different database. :) Cassandra was not designed for this.

If you NEED to use Cassandra, then take a look at this answer that's based on how eBay organizes their data.

But again, if you have the option, use another technology for this use case. This will be very messy in Cassandra.

Related