Reputation: 5211
If I want to create a DynamoDB table with ItemId
and BatchId
and I want to be able to query by ItemId
and BatchId
do I have to create two tables:
Table1: Hash-ItemId Range-BatchId
Table2: Hash-BatchId Range-ItemId
Or is there a way to use secondary indexes to avoid duplication?
Upvotes: 0
Views: 429
Reputation: 3614
how about a global secondary index on Table1 with BatchId as hash key?
Reopen because I think this answer is useful. Please correct me instead of closing the answer. @rfornal @Devin.
Hey @Nickolay I saw your comments below. Range key of base table CAN be used as hash key of GSI.
To prove that I created a table like this:
Base table: HashKey: hash + RangeKey:range
GSI table: HashKey: range + Rangekey: hash
Inserted some keys:
query base table:
query gsi:
Upvotes: 1