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년 전1517회 조회
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
답변함 일 년 전
profile picture
전문가
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠