- Newest
- Most votes
- Most comments
The issue you're experiencing with multiple sort key fields in your AWS AppSync GraphQL API is not uncommon. When using multiple sort key fields in an @index directive, there are some limitations and specific behaviors to be aware of.
First, it's important to note that when you define multiple sort key fields, they are combined into a single composite sort key. In your case, "topicType" and "regionLevelThree" are combined into a composite sort key named "topicTypeRegionLevelThree".
When querying an index with multiple sort key fields, you need to provide conditions for all the fields in the order they are defined. In your query, you're using the "eq" operator, which requires an exact match for both fields. This might be too restrictive and could be the reason you're getting empty results.
To troubleshoot this issue:
-
Ensure that you have data in your table that exactly matches the conditions you're querying for.
-
Try using a more flexible query condition. Instead of "eq", you could use "beginsWith" to match partial values:
topicTypeRegionLevelThree: {beginsWith: {topicType: "1", regionLevelThree: "2-1-1"}}
-
If you need to query based on only one of the sort key fields, you might need to create separate indexes for each field.
-
Double-check that the data types of your sort key fields match what's defined in your schema.
-
Verify that the status field is indeed part of your partition key as implied by your query.
If these suggestions don't resolve the issue, you might be encountering a limitation or bug in the current implementation of multiple sort key fields in AWS Amplify. In that case, you may need to consider alternative index designs or reach out to AWS support for further assistance.
Sources
Query - Amazon DynamoDB
Use Amplify with MySQL | AWS re:Post
Unauthorized running AppSync Query | AWS re:Post
answered 2 years ago
Relevant content
asked 4 years ago

Thank you for the suggestions, but I've already tried all these approaches without success:
I've verified the data exists and matches the query conditions I've tested both eq and beginsWith operators I've confirmed the data types are correct I've even tried querying without any conditions The core issue seems to be that queries with multiple sort key fields (sortKeyFields) consistently return empty results, while the same queries work perfectly when using only one sort key field. This behavior appears to be systematic rather than data-related.
Looking at GitHub issue #1438, others have reported the same problem, suggesting this might be a limitation or bug in the current AWS Amplify implementation.
Could you provide any specific working examples of multiple sort key fields queries? Or suggest alternative approaches that have been proven to work?