我试图了解DynamoDB表是如何与GSI一起工作的,我对它们的文档感到非常困惑。
在这个链接中,音乐库表以类似于JSON的格式显示如下(如果我正确理解的话):
// Music Library Table
[
{
"song_id": "song-129", // Partition Key
"details": { /** details is a Sort Key */
"title": "Wild Love",
"artist": "Argyboots",
"downloads": 15000,
// etc.
},
"month-2018-01": { /** Also a Sort Key? */
"month": "2018-01", /** GSI Primary Key */
"month_total": 1000 /** GSI Secondary Key */
},
"download_id_1": { /** Also a Sort Key? */
"time": "timestamp"
},
"download_id_2": { /** Also a Sort Key? */
"time": "timestamp"
},
"download_id_3": { /** Also a Sort Key? */
"time": "timestamp"
},
}
]似乎有几种Primary Keys = (Partition Key + Details / Month / DownloadID)的组合。但他们写了
和排序-Key=DownloadID
同样从这个链接中,HR表看起来如下所示:
// HR Table
[
{
"employee_id": "hr-974", /** Partition Key */
"employee_name": { /** Also a Sort Key? */
"name": "Murphy, John",
"start_date": "2008-11-08",
// etc.
},
"YYY-Q1": { /** Also a Sort Key? */
"order_total": "$5,000",
"name": "Murphy, John"
},
// ...
"v0_job_title": { /** Also a Sort Key? */
"job_title": "operator-1",
"start_date": "2008-11-08",
// etc.
},
"v1_job_title": { /** Also a Sort Key? */
"job_title": "operator-2",
"start_date": "2008-11-10",
// etc.
}
}
]但似乎并不是因为:
通过搜索仓库ID (如Warehouse_01),使用全局辅助索引查找在特定仓库中工作的所有员工。
仓库似乎有自己的条目,有自己的ID。
那么,JSON格式的表应该是什么样的呢?
发布于 2019-03-29 16:39:10
这个图表有点混乱,但“细节”、“2018-01月”等并不都是单独的排序键。它们实际上都在一个“排序键”下,同样的方式,"Song-129“不是分区键,而是在分区键"song_ID”下。
为了使事情更清楚,在JSON格式中如下所示:
// Music Library Table (if this is a list containing all individual items in the table)
[
{
"song_id": "song-129", // Partition Key
"sort_key": "details", // Sort Key
"title": "Wild Love",
"artist": "Argyboots",
"downloads": 15000,
// etc.
},
{
"song_id": "song-129", // Partition Key
"sort_key": "month-2018-01", // Sort Key
"month": "2018-01", // GSI Partition Key
"month_total": "1000" // GSI Sort Key
},
{
"song_id": "song-129", // Partition Key
"sort_key": "download_id_1", // Sort Key
"time": "timestamp"
},
{
"song_id": "song-129", // Partition Key
"sort_key": "download_id_2", // Sort Key
"time": "timestamp"
},
{
"song_id": "song-129", // Partition Key
"sort_key": "download_id_3", // Sort Key
"time": "timestamp"
},
]https://stackoverflow.com/questions/55419724
复制相似问题