[英]Is there a way to get a specific range of results in a DynamoDB query?
I am querying a DynamoDB table with table.query()
.我正在使用
table.query()
查询 DynamoDB 表。 I found that a FilterExpression
can filter the results further, but I can't seem to find a way to simply filter a range of the results.我发现
FilterExpression
可以进一步过滤结果,但我似乎找不到一种方法来简单地过滤一系列结果。
What I mean is that if the table has say 100 items, and the query matches 20 of them, is there a way to get say items 11-15 from those 20?我的意思是,如果表中有 100 个项目,并且查询匹配其中的 20 个,有没有办法从这 20 个项目中获取 11-15 个项目?
Thanks in advance!提前致谢!
Yes, both in Query/Scan you can set batch limit(Number of items to want to read).是的,在查询/扫描中,您都可以设置批量限制(要阅读的项目数)。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.