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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ