I have a dynamodb table has a partition key as ID
and sort key timestamp
. I need to query the table to find the latest 100 rows based on timestamp
column. When I check the query
API, I must specify the KeyConditions or KeyConditionExpression
. I don't want to query partition key in this case. How can I do that?
The scan
operation doesn't seem support sort the result.
One solution I can think of is to add an attribute on the table, let say status
and assign the same value for every rows in this table. Then create a GSI on the table with the partition key as status
and timestamp
as sort key. Then I can query the table with partition key is equal to OK
and sort the result based on timestamp
. However, this solution doesn't work well in terms of scale. The GSI will not be scaled well since every row in the table has the same value for status
.
So what is the best solution to my problem? Shouldn't I consider using dynamodb?