问题描述
我正在使用 table.query()
查询 DynamoDB 表。我发现 FilterExpression
可以进一步过滤结果,但我似乎找不到简单过滤一系列结果的方法。
我的意思是,如果表中有 100 个项目,并且查询匹配其中的 20 个,是否有办法从这 20 个项目中获取第 11-15 个项目?
提前致谢!
解决方法
是的,在查询/扫描中您都可以设置批量限制(要阅读的项目数)。
QueryRequest queryRequest = new QueryRequest()
.withTableName(TABLE_NAME)
.withKeyConditionExpression("query_condition")
.withIndexName("index_name") // If you have any
.withExpressionAttributeValues("Expression_values")
.withScanIndexForward(false) // To sort the results,only supported in Query. Not in Scan
.withLimit(LIMIT) // Batch Size/Limit
.withExclusiveStartKey(lastKeys); // Set the LastEvaluatedKey,if not it can NULL
QueryResult result = ddb.query(queryRequest);
Map<String,AttributeValue> lastKeys = result.getLastEvaluatedKey(); // You can pass these keys in your next call