indexing - 如果总是需要键,我如何制作稀疏索引?

标签 indexing amazon-dynamodb

我对 DynamoDB 中的某些东西感到非常困惑:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GuidelinesForLSI.html#GuidelinesForLSI.SparseIndexes

For any item in a table, DynamoDB will only write a corresponding index entry if the index sort key value is present in the item. If the sort key does not appear in every table item, the index is said to be sparse.

[...]

To track open orders, you can create an index on CustomerId (partition key) and IsOpen (sort key). Only those orders in the table with IsOpen defined will appear in the index.


但是,如果您使用备用排序键定义了 LSI,则在创建新项目时,备用排序键永远不能为空。因此,索引根本不是稀疏的,因为我创建的每个项目都会在索引中结束。
我错过了什么?

最佳答案

所以我终于想通了。我应该澄清我使用的是 AWS 控制台。

我创建了一个 GSI 作为测试,分区键是 Gpart和排序键 Gsort .我注意到当我创建一个新项目时,这些字段是自动添加的,我不能将它们留空,这就是我卡住的地方。 (我会收到错误“一个或多个参数值无效:一个 AttributeValue 可能不包含空字符串”)

enter image description here

事实证明,我需要做的实际上只是删除这些字段。

enter image description here

删除任何 GSI 或 LSI 相关属性后,我可以保存该项目,果然,这些索引仅显示那些键存在的项目。

关于indexing - 如果总是需要键,我如何制作稀疏索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48575985/

相关文章:

javascript - 如何使用图像的特定索引打开 fancybox

python - 将 Pandas 数据框切成两部分

node.js - 在 lambda 函数中为 dynamodb 生成唯一键

amazon-web-services - 如何设计 DynamoDB 表架构

java - Amazon Lambda Java 函数不向 DynamoDB 插入数据

database - 如何在 DynamoDB 中创建 UUID?

mysql - 在主键+外键上创建多重索引是否有性能优势?

python - 合并具有不同索引的 pandas 系列(在一个索引上对齐)

database - 根据前缀在表中查找单词

amazon-web-services - 有没有办法清除 dynamoDB 流?