Amazon dynamodb DynamoDB正在忽略索引的使用

Amazon dynamodb DynamoDB正在忽略索引的使用,amazon-dynamodb,Amazon Dynamodb,我有一张叫做银行对账单的dynamoDB表格 它有一个主分区键:- 名称:TransactionID(编号) 它有一个索引:- 名称:语句类型索引 状态:活动 类型:GSI 分区键:语句类型(字符串) 在StatementType列中有几个标记为“RBS”的记录 我是用C写的: public异步任务GetRecordList() { 尝试 { var请求=新的QueryRequest { TableName=“银行对账单”, KeyConditionExpression=“Stateme

我有一张叫做银行对账单的dynamoDB表格

它有一个主分区键:-

  • 名称:TransactionID(编号)
它有一个索引:-

  • 名称:语句类型索引
  • 状态:活动
  • 类型:GSI
  • 分区键:语句类型(字符串)
在StatementType列中有几个标记为“RBS”的记录

我是用C写的:

public异步任务GetRecordList()
{
尝试
{
var请求=新的QueryRequest
{
TableName=“银行对账单”,
KeyConditionExpression=“StatementType=:searchKey”,
ExpressionAttributeValues=新字典{
{“:searchKey”,新属性值{S=“RBS”}}
};
var response=await dynamoDbClient.QueryAsync(请求);//此处发生错误
foreach(响应中的字典项.Items)
{
//对这个项目做些什么
}
}
捕获(例外e)
{
logger.Info(“获取记录列表时失败”);
logger.Info(“错误:+e.Message”);
}
返回“完成”;
}
我收到以下错误“查询条件缺少关键架构元素:TransactionID”


当我使用StatementType索引作为键时,为什么会出现这种情况?

在另一个教程中,我发现了以下设置:

IndexName=“语句类型索引”

此代码适用于:

public async Task<string> GetRecordList()
{
    try
    {
        var request = new QueryRequest
        {
            TableName = "Bank-Statements",
            IndexName = "StatementType-index",
            KeyConditionExpression = "StatementType = :searchKey",
            ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
                {":searchKey", new AttributeValue { S =  "RBS" }}}
        };

        var response = await dynamoDbClient.QueryAsync(request);  //Error occurs here

        foreach (Dictionary<string, AttributeValue> item in response.Items)
        {
    //do something with item
        }
    }
    catch (Exception e)
    {
        logger.Info("Failed while Getting Record List");
        logger.Info("Error: " + e.Message);
    }

    return "DONE";
}
public异步任务GetRecordList()
{
尝试
{
var请求=新的QueryRequest
{
TableName=“银行对账单”,
IndexName=“StatementType索引”,
KeyConditionExpression=“StatementType=:searchKey”,
ExpressionAttributeValues=新字典{
{“:searchKey”,新属性值{S=“RBS”}}
};
var response=await dynamoDbClient.QueryAsync(请求);//此处发生错误
foreach(响应中的字典项.Items)
{
//对这个项目做些什么
}
}
捕获(例外e)
{
logger.Info(“获取记录列表时失败”);
logger.Info(“错误:+e.Message”);
}
返回“完成”;
}

Yep,您必须告诉DDB查询表或特定索引。它不像RDB那样自动“使用”索引。
public async Task<string> GetRecordList()
{
    try
    {
        var request = new QueryRequest
        {
            TableName = "Bank-Statements",
            IndexName = "StatementType-index",
            KeyConditionExpression = "StatementType = :searchKey",
            ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
                {":searchKey", new AttributeValue { S =  "RBS" }}}
        };

        var response = await dynamoDbClient.QueryAsync(request);  //Error occurs here

        foreach (Dictionary<string, AttributeValue> item in response.Items)
        {
    //do something with item
        }
    }
    catch (Exception e)
    {
        logger.Info("Failed while Getting Record List");
        logger.Info("Error: " + e.Message);
    }

    return "DONE";
}