AWS错误代码:ValidationException,AWS错误消息:全局二级索引不支持一致性读取

时间:2014-02-06 07:44:26

标签: amazon-dynamodb

我开始使用Amazon DynamoDB并遇到查询问题。

我有一个表Dev_Testgame1_Mail,其中id为主哈希键,后跟三个全局二级索引,

  1. fromPlayerId(Hash Key)
  2. toPlayerId(哈希键)+ isRead(范围键)
  3. toPlayerId(哈希键)+ endDate(范围键)
  4. 我有上面的代码来进行查询,

    **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错误消息:全局二级索引不支持一致读取

    在这个问题上,我们非常感谢您的帮助。

    由于 阿伦

1 个答案:

答案 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正在为你做任何事情。