Reputation: 8140
I'm trying to set up a new DynamoDB table and I'm planning to use the Local Secondary Indexes (LSI) for the first time.
However, I'm finding myself struggling creating them. I don't find any reference in the Amazon API in creating LSI's with composed hash keys (Hash key that exists out of more than one attribute).
This is how my model looks like, it represent a message send from UserA to UserB:
The queries that I would like to do are the following
For the hashKey I have chosen UserAId, Range key is dateTIme. This should cover the query that I need to execute the most (query 1) and should spread out the data evenly.
For the other queries, I was thinking about the following LSI's
My questions are:
'KeySchema' => array( array('AttributeName' => 'UserAId', 'KeyType' => 'HASH'), array('AttributeName' => 'status', 'KeyType' => 'RANGE'), ),
So how do I define there to use status-isNesLetter for example?
Thanks in advance
Upvotes: 1
Views: 275
Reputation: 8140
After doing some research and some testing, I can now answer my own question.
Question 1) No, you cannot define composed range keys in the keyschema. You can however create seperate attributes in your model class to represent the same thing
Example: For Query 3 you would need to add a new attribute to the model and do the merging of the attributes status and dateTime yourself.
Question 2) Yep. You can also use ScanIndexForward to change the order to DESC/ASC
Upvotes: 1