我开始使用Amazon DynamoDB并遇到查询问题。
我有一个表Dev_Testgame1_Mail,其中id为主哈希键,后跟三个全局二级索引,
我有上面的代码来进行查询,
**DynamoDBMail hashKObject = new DynamoDBMail();
hashKObject.setToPlayerId(playerId);
Condition endDateRangeKeyCondition = new Condition();
//endDateRangeKeyCondition.withComparisonOperator(ComparisonOperator.NULL).withAttributeValueList(new AttributeValue().withB(Utils.convertDateToByteBuffer(DateUtil.getUtcDateTime())));
endDateRangeKeyCondition.withComparisonOperator(ComparisonOperator.NULL);
DynamoDBQueryExpression<DynamoDBMail> queryExpression = new DynamoDBQueryExpression<DynamoDBMail>();
queryExpression.withHashKeyValues(hashKObject).withRangeKeyCondition("endDate", endDateRangeKeyCondition);
queryExpression.withIndexName("gsi_tp_enddt").withLimit(pageSize).withScanIndexForward(false);
return dynamodbMapper.queryPage(DynamoDBMail.class, queryExpression, new DynamoDBMapperConfig(TableNameOverride.withTableNamePrefix(Utils.getDynamoDBTableNamePrefix(gameId, env))));**
我收到以下错误,
com.amazonaws.AmazonServiceException:状态代码:400,AWS服务:AmazonDynamoDBv2,AWS请求ID:GUUBV24K2O40T276R9NNN0EKB7VV4KQNSO5AEMVJF66Q9ASUAAJG,AWS错误代码:ValidationException,AWS错误消息:全局二级索引不支持一致读取
在这个问题上,我们非常感谢您的帮助。
由于 阿伦
答案 0 :(得分:15)
将queryExpression
的一致读取属性设置为false
。把这一行:
queryExpression.withConsistentRead(false);
或
queryExpression.setConsistentRead(false);
之前打电话
return dynamodbMapper.queryPage(DynamoDBMail.class, queryExpression, new DynamoDBMapperConfig(TableNameOverride.withTableNamePrefix(Utils.getDynamoDBTableNamePrefix(gameId, env))));
顺便说一句,我不认为你NULL
RangeKeyCondition
正在为你做任何事情。