Sort by ID filtering by date interval DynamoDB

I want to be able to filter items in a table given a date interval, and still sort the results by their IDs.

I understand I could use the between operation in the SK to query the dates, although, this creates the constraint of not allowing the results to be sorted by the item ID. Considering the following GSI scheme:

gsi_1 : {
  "pk": { "item_type" }
  "sk": { date }

My query to get the items contained in a date interval would look like:

"IndexName": "Gsi1Index",
"KeyConditionExpression": "gsi_1_pk = :item_type and gsi_1_sk between :date_start and :date_end"

Is it possible to still sort the results by ID?

I'm not attached to any specific GSI scheme, any new modeling ideas to allow such query are welcome.

Read more here:

Content Attribution

This content was originally published by andreybleme at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: