有没有办法在 DynamoDB 查询中获得特定范围的结果?

问题描述

我正在使用 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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...