Filter Expression can only contain non-primary key attributes ?

6

DynamoDB currently does not allow FilterExpression on your GSI hash or sort keys. Hash or sort key should be specified using KeyCondition only. I understand this is made to protect us from making mistakes, but it also removes the ability of doing some pretty good things.

As an example, I am working on a table that has relationships from users to resources. In a simplified example, imagine:

PK|user#SoMeId      SK|resourceA#rEsOuRcEiD       NAME|-nice-slug-name-

I want to be able to search in "NAME" using "contains", and I would also like to have my list sorted by it, as it is more natural for users than random ids. If I could use a sort key in both KeyExpression and FilterExpression, I could create a GSI using PL/NAME, append prefix to name as well, and have a nice search index.

PK|user#SoMeId     SK|resourceA#rEsOuRcEiD     NAME|resourceA#-nice-slug-name-
query (PK=user#SoMeId, SK=begins_with(resourceA), INDEX=pk-name-index, FILTER={ name: contains(slug) })

That would be very nice. Judging by I understand DynamoDB works, it seems like this should be completely possible from the technical perspective.

Why don't you guys force an extra argument to enable functionality? Instead of outright banning it, just offer the ability of setting something like AllowKeyFilter=true on the API calls, just to make it an obvious opt-in feature, so no one can complain if they pay more than expected in case they made something wrong?

When I asked this question on the past, I have been told to duplicate fields, but that's just cumbersome. Why not allow it to be used by those that opt-in?

(Continued from https://forums.aws.amazon.com/thread.jspa?threadID=172530)

已提问 2 年前1515 查看次数
1 回答
0

To my knowledge, you have correctly identified how the service is working. Your best course of action is likely to provide feedback to the Amazon DynamoDB service team through the AWS Management Console. Some details on doing that are here: https://repost.aws/knowledge-center/send-feedback-aws

AWS
已回答 1 年前
profile picture
专家
已审核 1 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则