AWS Appsync - 查询 DynamoDB 的空索引

AWS Appsync - Query DynamoDB for null indices

我想获取附加到 AppSync 架构的 Query 的 DynamoDB table,以便仅获取 null 或空 值具有全球二级索引 (GSI) 的属性。

我尝试了以下方法但无法得到结果:

Throws [Invalid operator used in KeyConditionExpression: OR] :

"operation" : "Query",
"index" : "myAttrIndex",
"query" : {
    "expression" : "attribute_not_exists(myAttr) or myAttr = :null",
    "expressionValues" : {
        ":null" : { "NULL" : null }
    }
}

Throws [Invalid operator used in KeyConditionExpression: attribute_not_exists] :

"operation" : "Query",
"index" : "myAttrIndex",
"query" : {
    "expression" : "myAttr = :null",
    "expressionValues" : {
        ":null" : { "NULL" : null }
    }
}

Throws [One or more parameter values were invalid: Condition parameter type does not match schema type] :

"operation" : "Query",
"index" : "myAttrIndex",
"query" : {
    "expression" : "myAttr = :null",
    "expressionValues" : {
        ":null" : { "NULL" : null }
    }
}

如何编写查询文档过滤掉字符串属性的非空值?

默认情况下,全球二级指数是稀疏的。

For any item in a table, DynamoDB will only write a corresponding entry to a global secondary index if the index key value is present in the item. For global secondary indexes, this is the index partition key and its sort key (if present). If the index key value(s) do not appear in every table item, the index is said to be sparse.

如果您需要 myAttr 属性空值包含在 GSI table 中,您可以设置一个虚拟值(例如 "NULL"),然后查询该值。请注意,所有 table 项现在都将包含在 GSI table 中,这会增加您的费用。

更多详情: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-general-sparse-indexes.html