在主键以外的字段上查询 DynamoDb
Query DynamoDb on a field other then the primary key
我用 C# 创建了一个发电机 table。这是table
的定义
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; }
}
到目前为止,为了从 table 获取数据,我使用的是
[DynamoDBHashKey]public string SystemId { get; set; }
从 dynamo 获取记录的代码是这样的
var config = new DynamoDBOperationConfig{
OverrideTableName = table
};
var email = await _dynamoDBContext.LoadAsync<EmailArchive>(systemId, config);
一切正常,但是现在我想在另外两个列上查询此 table
[DynamoDBProperty]public string Status { get; set; }
[DynamoDBProperty]public string CaseId { get; set; }
能否举例说明如何查询带有附加列的 table?
您需要添加 secondary index。
如果您在进行查询时知道 SystemId,则为本地二级索引 (LSI); LSI 具有与 table 相同的 has 键,但排序键不同。
全球二级索引 (GSI) 如果您只有 Status、CaseId; GSI 支持与原始 table.
不同的哈希和排序键
注意:添加 LSI 需要删除并重新创建 table。
我用 C# 创建了一个发电机 table。这是table
的定义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; }
}
到目前为止,为了从 table 获取数据,我使用的是
[DynamoDBHashKey]public string SystemId { get; set; }
从 dynamo 获取记录的代码是这样的
var config = new DynamoDBOperationConfig{
OverrideTableName = table
};
var email = await _dynamoDBContext.LoadAsync<EmailArchive>(systemId, config);
一切正常,但是现在我想在另外两个列上查询此 table
[DynamoDBProperty]public string Status { get; set; }
[DynamoDBProperty]public string CaseId { get; set; }
能否举例说明如何查询带有附加列的 table?
您需要添加 secondary index。
如果您在进行查询时知道 SystemId,则为本地二级索引 (LSI); LSI 具有与 table 相同的 has 键,但排序键不同。
全球二级索引 (GSI) 如果您只有 Status、CaseId; GSI 支持与原始 table.
不同的哈希和排序键注意:添加 LSI 需要删除并重新创建 table。