如何在DynamoDB中查询GSI时为范围键指定多个值?

时间:2017-01-27 10:43:52

标签: amazon-dynamodb aws-sdk aws-java-sdk

我有一个部门表和一个GSI,其中“租户”作为散列键,“dept_name”作为范围键。这两个字段都是String类型。 我想查询GSI以获得在[工程,销售,设施]中具有dept_name的租户的部门。我如何实现这一目标?

我使用了以下代码,仍无法获得结果。

  public List<Dept> getDepartments(String tenant,  List<String> depts) {
        Dept dept = new Dept();
        dept.tenant = tenant;
        DynamoDBQueryExpression<Dept> queryExpression = new DynamoDBQueryExpression<>();
        Condition rangeKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.IN);
        rangeKeyCondition.withAttributeValueList(new AttributeValue().withSS(depts));
        queryExpression.withIndexName("tenant_dept_index").withRangeKeyCondition("dept", rangeKeyCondition);
        queryExpression.withHashKeyValues(dept);
        //For GSI consistent read is always false
        queryExpression.setConsistentRead(false);
        List<Dept> items = mapper.query(Dept.class, queryExpression);
        return items;
      }

感谢。

0 个答案:

没有答案