douhai9043 2019-06-12 19:30
浏览 237
已采纳

在Golang中查询DynamoDB上的二级索引

My primary key is a field called "id"

I've added a secondary index to my table on the field "group_number"

enter image description here

I query via the secondary index like so:

// Query the secondary index
queryInput := &dynamodb.QueryInput{
    TableName: aws.String(c.GetDynamoDBTableName()),
    KeyConditions: map[string]*dynamodb.Condition{
        "group_number": {
            ComparisonOperator: aws.String("EQ"),
            AttributeValueList: []*dynamodb.AttributeValue{
                {
                    S: aws.String(c.GroupNumber),
                },
            },
        },
    },
}

However; I get the error "validationexception: query condition missed key schema element: id"

Does DynamoDB only allow the querying of primary keys? I was under the impression you use "GetItem" for primary key being that only one record can come back if you use a primary key. To search via secondary indexes you use "Query", and to search by non-index keys, you use "Scan".

Please let me know what I'm doing incorrectly here.

  • 写回答

1条回答 默认 最新

  • duanjuelu8874 2019-06-13 02:21
    关注

    In addition to the TableName, You need to also specify the IndexName property when creating the QueryInput to query the index.

    https://docs.aws.amazon.com/sdk-for-go/api/service/dynamodb/#QueryInput

    // The name of an index to query. This index can be any local secondary index
    // or global secondary index on the table. Note that if you use the IndexName
    // parameter, you must also provide TableName.
    IndexName *string `min:"3" type:"string"`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog