How to compute top X in last Y days?

I am new to Aerospike. I want to show a widget on my site that shows the most visited 50 courses in last 7 days. I was thinking about how to get this data from aerospike. Can you suggest a suitable data model for the above case? There may be 3000 courses in total.

May be something on the lines -

Day1 (key) : {courseId1 : 2, courseId2 : 3, courseId3 : 45}

Day2 (key) : {courseId1 : 2, courseId2 : 3, courseId3 : 45, courseId4 : 32}

Also, I want to know if I can perform such aggregations like summing the count of courses over 7 days and return the top 50 ones?

So here’s what I did.

I maintained a courseId to views map for every week. The map maintains the total views on a course in last 1 week.

Suppose I receive a view on courseId1 on date 20th Oct, so I increment its view count in 7 maps.

Key (20201014-20201020) : {courseId1 : 1, courseId:3}
Key (20201015-20201021) : {courseId1 : 1}
Key (20201016-20201022) : {courseId1 : 1}
Key (20201017-20201023) : {courseId1 : 1}
Key (20201018-20201024) : {courseId1 : 1}
Key (20201019-20201025) : {courseId1 : 1}
Key (20201020-20201026) : {courseId1 : 1}

Suppose I need to fetch top 50 viewed courses in last 7 days on 26th Oct, I just perform a getByRank operation on the map of record Key (20201020-20201026).

So when fetching top K, I just use aerospike rank operation. But for every view, I have to increment 7 maps, since the view on that course will be used for fetching top K for the next 7 days.

My concern is do I need a sorted aerospike map in this case? I am currently using unsorted map since I am always sorting by value (ie, views).

If someone knows of any better approach, please let me know.

© 2015 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.