Amazon web services DynamoDB-查询范围键的最大值
我有一个DynamoDB表,它的结构如下Amazon web services DynamoDB-查询范围键的最大值,amazon-web-services,amazon-dynamodb,secondary-indexes,Amazon Web Services,Amazon Dynamodb,Secondary Indexes,我有一个DynamoDB表,它的结构如下 HK | RK | A1 | A2 | A3 (Hash Key) | (Range Key) 我有一个本地二级索引,其范围键为A3 我想找出特定的散列键HK,属性A3的最大值是多少。所以我像这样查询二级索引: Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":v1", new AttributeValu
HK | RK | A1 | A2 | A3
(Hash Key) | (Range Key)
我有一个本地二级索引,其范围键为A3
我想找出特定的散列键HK,属性A3的最大值是多少。所以我像这样查询二级索引:
Map<String, AttributeValue> eav = new HashMap<>();
eav.put(":v1", new AttributeValue().withS("hash value"));
queryExpression = new DynamoDBQueryExpression<Table>()
.withIndexName("index-name")
.withKeyConditionExpression("HK = :v1")
.withExpressionAttributeValues(eav)
.withScanIndexForward(false); //This will sort the result in descending order (w.r to range key)
queryExpression.setLimit(1);
myCollection = dynamoDBMapper.query(Table.class, queryExpression);
Map eav=newhashmap();
eav.put(“:v1”,新的AttributeValue()。带有(“哈希值”);
queryExpression=new DynamoDBQueryExpression()
.withIndexName(“索引名”)
.withKeyConditionExpression(“HK=:v1”)
.带有表达式属性值(eav)
.使用CANINDEXFORWARD(假)//这将按降序对结果进行排序(从w.r到范围键)
queryExpression.setLimit(1);
myCollection=dynamoDBMapper.query(Table.class,queryExpression);
问题在于,它返回所有带有指定哈希键的记录,并按范围键(A3)进行反向排序。我想独自拿第一张唱片。(给定香港A3值最大的记录)
我尝试使用setLimit,但它不起作用
如何实现这一点。我使用
queryPage
而不是query
QueryResultPage<Lookup> res = dynamoDBMapper.queryPage(Table.class, queryExpression);
QueryResultPage res=dynamoDBMapper.queryPage(Table.class,queryExpression);
更多信息