首页 > 解决方案 > 对 DynamoDB 中的 GSI 进行批量查询?

问题描述

是否可以在 GSI 上使用 DynamoDBMapper 同时对多个哈希键值创建单个查询?例如,如果我尝试使用 GSI 获取表 Table 中的所有相关记录,我将遍历我的所有哈希键值并对每个哈希键值进行单独查询。

即目前我正在做

    for (String s : listOfStrings) {
      Attribute thing = new Attribute();
      thing.setSomeField(s);
      DynamoDBQueryExpression<Attribute> queryExpression = 
         new DynamoDBQueryExpression<Attribute>()
            .withHashKeyValues(thing)
            .withIndexName("example-GSI")
            .withConsistentRead(false);
    }

但我想在批处理调用而不是 for 循环中完成所有操作。

我检查了 DynamoDBMapper 文档,似乎没有,但我只是想知道这里是否有人对这种情况有任何好的解决方案。

标签: amazon-web-servicesamazon-dynamodbaws-sdkdynamodb-queriestable-index

解决方案


不,DynamoDB 不支持。当我需要对多个哈希键运行查询时,我使用循环并一次查询一个。如果您愿意,也可以发送并行请求。


推荐阅读