1

I am just starting working in dynamodb and I want to set some indexes correctly. I have a table with objects with the following fields:

id -> unique id for every object
businessType -> not unique, you can have multiple objects with the same business type
checkType -> not unique, you can have multiple objects with the same check type
...other fields (not important)

Now i want to be able to query efficiently without scanning:
1) Query by businessType only, get all objects with specific businessType
2) Query by businessType and checkType, get all objects with specific businessType AND checkType
3) Query by id only, get the object with unique id

How do i set indexes efficiently to accomplish above ?
Thank you.

Michael G
  • 13
  • 4

2 Answers2

0

Query by businessType only, get all objects with specific businessType :

Créateur an index onk 2) Query by businessType and checkType, get all objects with specific businessType AND checkType 3) Query by id only, get the object with unique id

Sid Ali
  • 1,779
  • 4
  • 17
  • 38
0

Use id as the hash key of the table. Create one index that uses businessType as the hash key and checkType as the sort key.

Your queries:

  1. Query the index, without specifying a value for the sort key.
  2. Query the index, and specify both the businessType and the checkType. (The primary key for an index is not required to be unique, so you can get multiple items with this query.)
  3. Use get-item to load a single object by its id.
Matthew Pope
  • 7,212
  • 1
  • 28
  • 49