在主键以外的字段上查询DynamoDb



我已经从c#创建了一个dynamo表。这是表的定义

public class EmailArchive
{
[DynamoDBHashKey]
public string SystemId { get; set; }
[DynamoDBProperty]
public string EmailMessageId { get; set; }
[DynamoDBProperty]
public string Status { get; set; }
[DynamoDBProperty]
public string CaseId { get; set; }
[DynamoDBProperty]
public string Headers { get; set; }
}

到目前为止,我使用从表中提取数据

[DynamoDBHashKey]public string SystemId { get; set; }

从发电机中获取记录的代码是这个

var config = new DynamoDBOperationConfig{
OverrideTableName = table
};
var email = await _dynamoDBContext.LoadAsync<EmailArchive>(systemId, config);

这一切都很好,但现在我想在的另外两列上查询这个表

[DynamoDBProperty]public string Status { get; set; }
[DynamoDBProperty]public string CaseId { get; set; }

你能展示一个如何查询带有附加列的表的例子吗?

您需要添加一个辅助索引。

本地二级索引(LSI(,如果您在查询时知道SystemId;LSI具有与表相同的has关键字,但具有不同的排序关键字。

全球二级指数(GSI(,如果你只有状态,CaseId;GSI支持不同的散列&对原始表中的键进行排序。

注:添加LSI需要删除并重新创建该表。

最新更新