【问题标题】:DynamoDB Querying using Global Secondary IndexDynamoDB 使用全局二级索引查询
【发布时间】:2018-11-15 18:28:08
【问题描述】:

我正在尝试查询上周创建的所有行。我为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);

【问题讨论】:

    标签: amazon-dynamodb


    【解决方案1】:

    我已阅读您的案例,因此对于您想要的输出,您不应该创建“created”作为索引 bz 它成为表的关键,并且在 keyCondition 中您不能使用 GT 和 LT 运算符。

    您需要使用 FilterExpression,并且可以在“created”字段中使用 GT 和 LT。

    【讨论】:

    • 感谢您的快速回复。如果我使用FilterExpression,那么我必须将分区键作为ComparisonOperator.EQ 对吗?
    • 是的,它将在 keycondition 表达式中,而“created”字段条件在过滤器表达式中。
    • 无keycondition查询怎么办?
    • 这是必填字段,您必须提供分区键的键条件和创建字段的过滤表达式。
    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-09
    • 2021-03-30
    相关资源
    最近更新 更多