-3

my dynamodb structure is somehow for example my PK and SK is like

PK = USR#123ACT#234 and SK = AYT#<epoch_time>

and my global index are like

GSi3pk = ACT#234 and GSI3SK = <epoch_time>

now case is using global index I want to get data of last 30 days with account_id=234

newbiee
  • 93
  • 7

1 Answers1

0

To query for a specific primary key (of account number) and a timestamp in the last 30 days, you can query with some variant of this:

{
    "TableName": "orders",
    "IndexName": "gsi3",
    "KeyConditionExpression": "gsi3pk = :pk AND tstamp BETWEEN :start AND :end",
    "ExpressionAttributeValues": {
        ":pk": {
            "S": "ACT#234"
        },
        ":start": {
            "N": "1651962700"
        },
        ":end": {
            "N": "1654641000"
        }
    }
}
jarmod
  • 71,565
  • 16
  • 115
  • 122
  • thanks sir for reply . my question is I have only 1 field of time . how I can like query to start and end time ? – newbiee Jun 08 '22 at 07:33
  • The example query that I included has one timestamp attribute (that I've named `tstamp`). The `:start` and `:end`, if that's what you are referring to, are value placeholders, not attribute names. – jarmod Jun 08 '22 at 11:21
  • I am confuse about `tstamp` named field . I don't have any field named `tstamp` . it's `GSI3_UPDATED_ON` . can I use this like `GSI3_UPDATED_ON` BETWEEN :start AND :end" – newbiee Jun 08 '22 at 12:24
  • The name `tstamp` is an example. You didn't indicate what attribute contained the timestamp so I gave you an example. – jarmod Jun 08 '22 at 13:09