您可以添加一个表示天数的属性(您的GSI主键),并将timestamp属性设置为您的GSI排序键
| AuthorId | Timestamp(GSI SK) | DayAttribute (GSI PK) |
|:-----------:|------------------:|:---------------------:|
| authord_id | 1534522921 | 2018-08-17 |
| authord_id2 | 1534522922 | 2018-08-17 |
| authord_id3 | 1534522923 | 2018-08-18 |
当您查询GSI时,它将按时间排序。
编辑您的评论:
添加属性以满足查询需要不是一个好方法。在这种情况下,我建议按层次结构使用排序键。
这是桌子
| AuthorId | Timestamp(GSI SK) | MonthAttr (GSI PK) |
|:-----------:|----------------------------:|:---------------------:|
| authord_id | 2018:08:17::10:03:25 | 2018-08 |
| authord_id | 2018:08:17::10:03:25 | 2018-08 |
| authord_id | 2018:08:18::10:03:25 | 2018-08 |
begins_with
,您可以查询本月、10到15天之间或10到12小时之间的所有项目,依此类推。。
例如,对于过去13天的查询,SortKey条件将是
begins_with(2018:08:04:)
begins_with(2018:08:17:10:)
.
该方法引入了热分区密钥问题。看看
Time Series Data