我正在尝试查询最近一周创建的所有行。我已经为AWS console
中的created
键创建了一个索引。在我的查询中,我为created
密钥添加了带有ComparisonOperator.GT
的密钥条件。但当我运行查询时,它会抛出一个类似Query key condition not supported
的错误。如果我将条件给定为ComparisonOperator.EQ
,它将返回一行。但不适用于ComparisonOperator.GT
。
代码:
Condition rangeKeyCondition = new Condition();
rangeKeyCondition.withComparisonOperator(ComparisonOperator.GT).withAttributeValueList(new AttributeValue().withS("11:26 23/10/2018 "));
Map<String, Condition> keyConditions = new HashMap<String, Condition>();
keyConditions.put("created", rangeKeyCondition);
QueryRequest queryRequest = new QueryRequest();
queryRequest.withTableName(getTableName(TABLE_NAME));
queryRequest.withIndexName("created-index");
queryRequest.withKeyConditions(keyConditions);
QueryResult result = EventStoreInitializer.getAmazonDynamoDBClient().query(queryRequest);
我已经阅读了您的案例,因此对于您想要的输出,您不应该将"created"创建为索引bz,它将成为表的键,在keyCondition中,您不能使用GT和LT运算符。
您需要使用FilterExpression,在那里您可以使用GT和LT作为"已创建"字段。