【发布时间】:2021-06-13 04:06:26
【问题描述】:
我将以下数据存储在名为 elo-history 的 DynamoDB 表中。
{
"gameId": "chess",
"guildId": "abc123",
"id": "c3c640e2d8b76b034605d8835a03bef8",
"recordedAt": 1621095861673,
"results": [
{
"oldEloRating": null,
"newEloRating": 2010,
"place": 1,
"playerIds": [
"abc1"
]
},
{
"oldEloRating": null,
"newEloRating": 1990,
"place": 2,
"playerIds": [
"abc2"
]
}
],
"versus": "1v1"
}
我有 2 个索引,guildId-recordedAt-index 和 gameId-recordedAt-index。这些论文允许我查询这些字段。
我正在尝试为results[].playerIds[] 添加另一个索引。我希望能够使用playerId=abc1 查询记录,并像 guildId 和 gameId 一样对这些记录进行排序。 DynamoDB 是否支持类似的东西?我是否需要重组数据或以两种不同的格式保存数据以支持此类查询?
类似的东西。
除了 elo-history 表之外,还有一个名为 player-elo-history 的新表。这将按 playerId 存储游戏列表
{
"id": "abc1",
"gameId": "chess",
"guildId": "abc123",
"recordedAt": 1621095861673,
"results": [
[
{
"oldEloRating": null,
"newEloRating": 2010,
"place": 1,
"playerIds": [
"abc1"
]
},
{
"oldEloRating": null,
"newEloRating": 1990,
"place": 2,
"playerIds": [
"abc2"
]
}
]
]
}
{
"id": "abc2",
"gameId": "chess",
"guildId": "abc123",
"recordedAt": 1621095861673,
"results": [
[
{
"oldEloRating": null,
"newEloRating": 2010,
"place": 1,
"playerIds": [
"abc1"
]
},
{
"oldEloRating": null,
"newEloRating": 1990,
"place": 2,
"playerIds": [
"abc2"
]
}
]
]
}
【问题讨论】:
-
索引(作为其分区和排序键的一部分)只能包含字符串、数字或二进制类型的顶级属性。因此,您不能让索引使用嵌套值。如果您按照建议创建一个新表,我不知道您想要什么样的排序,但请记住排序仅通过排序键完成,如上所述,它必须是上述类型的顶级属性.
标签: amazon-dynamodb dynamodb-queries amazon-dynamodb-index amazon-dynamodb-data-modeling