When querying in DynamoDB (with a hash-and-range primary key), is it essential to provide the hash key or can you simply search by providing the range key? This is my use case: I have a table which has the following "schema": Category#Domain (String) - Hash key GroupType#GroupName (String) - Range key Some other string fields like UpdatedOn, UpdatedBy etc.
I have to frequently do there two things: 1. Given a Category#Domain, get all the matching items. 2. Given a GroupType#GroupName, get all the matching items.
Both the operations are fairly frequent so I do not want to use scan. Is there an effective way to do this in DynamoDB? Is there a better way to design the schema (more tables, secondary indexes etc.)? Any suggestion would be helpful. Someone suggested using Global Secondary Index but with that my question is will I be able to make the range key of my main table as the hash key of my gsi? I know all the "keys" are copied over automatically but this would help me only if I can make GroupType#GroupName as the hash key in the gsi so as to be able to query on it. Also, is there any special way to handle gsi from DynamoDBMapper? Will I need to create a new POJO?