如何在DynamoDB中创建复合GSI PK?
我尝试使用使用 business_ID,type_id,pantch_id 字段的PK创建GSI。我在AWS控制台中以两种不同的方式进行了操作:
首先:business_id#type_id#pantch_id
第二个:[business_id]#[type_id]#[pharts_id]
and key:更新已更新
这是查询:
SELECT *
FROM "items"."composite_key-index"
WHERE business_id = 435634652 AND type_id = 2 AND partner_id = 69992528
ORDER BY updated ASC
在两种情况下,它都会引发此错误:
验证exception:必须至少具有一个非访问的哈希密钥 使用订单时条件在Where子句中的条件。
如果我在没有订单的情况下运行它:
SELECT *
FROM "items"."composite_key-index"
WHERE business_id = 435634652 AND type_id = 2 AND partner_id = 69992528
即使有数据匹配这些值,也不会返回任何项目。
我在这里做错了什么?
I have tried creating GSI with a PK that uses a composite value of business_id, type_id, partner_id fields. I did it in two different ways in the AWS console:
First: business_id#type_id#partner_id
Second: [business_id]#[type_id]#[partner_id]
and sort key: updated
Here is the query:
SELECT *
FROM "items"."composite_key-index"
WHERE business_id = 435634652 AND type_id = 2 AND partner_id = 69992528
ORDER BY updated ASC
In both cases it throws this error:
ValidationException: Must have at least one non-optional hash key
condition in WHERE clause when using ORDER BY clause.
And if I run it without the order by:
SELECT *
FROM "items"."composite_key-index"
WHERE business_id = 435634652 AND type_id = 2 AND partner_id = 69992528
it doesnt return any items, even though there are data matching those values.
What am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要使用复合值作为键,您必须自己构建值。
您的应用程序必须将值存储在单个属性中,例如
435634652#2#6992528
然后您的查询看起来像
To use a composite value as a key, you have to build the values yourself.
Your application would have to store the value in a single attribute, ex GSI_PK, as
435634652#2#6992528
Then your query would look like