-1

I am new to DynamoDB so I'm still trying to understand how to use it, but I have what I believe is a simple task but I'm not sure how to address it.

I need to create a table to store categorized questions in which I need to store a click counter. So let's say something like this:

ID: 1
Question: What is this?
Category: General
Clicks: 100

Now, the problem is I need an optimized way to get the most general clicked questions and the most clicked questions by category, let's say a top 10.

In a classic SQL style it would be something like this:

SELECT ID, Question
FROM Questions
ORDER BY Clicks DESC
LIMIT 10

Can anyone point me in the right direction on how to structure the table? I tried the sorting but it always requires a hash key condition, so I don't understand how I can get this done as I need the top 10 results and not a single one.

Thanks in advance!

Damil
  • 97
  • 1
  • 5

1 Answers1

0

How are you accumulating the clicks, if you are able to figure out how you accumulate the clicksstream onto the table correctly that will be your answer.

You will need to implement a mechanism that maps incoming clicks to the item record being clicked on and increment it using an atomic counter. With this you will be able to then create a sparse index and sort it in descending order to get what you need.

dariusjs
  • 31
  • 2
  • Clicks go into a clicks attribute that gets incremented. That gives me the sort key but in order to do query operations a hash key is also requires so that’s where I get lost. – Damil Apr 20 '21 at 00:22
  • @Damil are you able to post some examples perhaps an existing DynamoDB workbench example you have, can try to get a better answer for you then. – dariusjs Apr 21 '21 at 11:01