DynamoDB:是否可以在不创建两个表的情况下按哈希和范围进行查询?

DynamoDB : Is it possible to query by hash and range without creating two tables?

如果我想用 ItemIdBatchId 创建 DynamoDB table 并且我希望能够通过 ItemIdBatchId 进行查询我必须创建两个 tables:

Table1: Hash-ItemId Range-BatchId
Table2: Hash-BatchId Range-ItemId

或者有没有办法使用二级索引来避免重复?

在 Table1 上使用 BatchId 作为哈希键的全局二级索引怎么样?

重新打开,因为我觉得这个答案很有用。请纠正我而不是关闭答案。 @rfornal @Devin.

嘿@Nickolay 我在下面看到了你的评论。 base table 的范围键可以用作 GSI 的哈希键。

为了证明我创建了一个这样的table:

Base table: HashKey: hash + RangeKey:range

GSI table: HashKey: range + Rangekey: hash

插入了一些键:

查询库table:

查询gsi: