简体   繁体   中英

DynamoDB GSI BatchGetItem

Is it possible to retrieve rows from the dynamodb Global secondary index using batchgetitem api? If my aim is to retrieve data from the main table based on some non-key attribute also, but data should be retrieved in the batch of 100 items - is the GSI index won't fit here?

Also is BatchItemGet API available for Query? Say a table has the primary key and sort key and same primary key can have multiple sort keys can I retrieve multiple primary keys using batchItemGet with just primary key only or it won't fir here?

There is no way to specify the index name in the BatchGetItem API operation according to the docs . That means using BatchGetItem (and GetItem for that matter) on a secondary index isn't possible. Both of these operate on the primary index.

If you want to retrieve data from a secondary index, you need to use Query or Scan . Both support the IndexName attribute according to the documentation . When using Query you have to specify the partition key and can optionally filter based on the sort key. If you don't filter on the sort key, you will get all items with the partition key, which should take care of your second requirement.

To retrieve data from a secondary index based on different partition keys, you'd need to issue multiple Query operations for the separate values of these keys, there is no batching here.

You can use PartiQL with WHERE IN clause for that:

SELECT * FROM Orders WHERE OrderID IN [100, 300, 234]

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.select.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM