简体   繁体   English

DynamoDB GSI BatchGetItem

[英]DynamoDB GSI BatchGetItem

Is it possible to retrieve rows from the dynamodb Global secondary index using batchgetitem api?是否可以使用 batchgetitem api 从 dynamodb 全局二级索引中检索行? 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?如果我的目标是也基于一些非键属性从主表中检索数据,但数据应该在 100 个项目的批次中检索 - GSI 索引不适合这里吗?

Also is BatchItemGet API available for Query? BatchItemGet API 也可用于查询吗? 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?假设一个表具有主键和排序键,并且相同的主键可以有多个排序键,我可以使用 batchItemGet 仅使用主键检索多个主键,还是不会在这里启动?

There is no way to specify the index name in the BatchGetItem API operation according to the docs .根据文档,无法在BatchGetItem API 操作中指定索引名称。 That means using BatchGetItem (and GetItem for that matter) on a secondary index isn't possible.这意味着无法在二级索引上使用BatchGetItem (和GetItem )。 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 .如果要从二级索引中检索数据,则需要使用QueryScan Both support the IndexName attribute according to the documentation .根据文档,两者都支持IndexName属性。 When using Query you have to specify the partition key and can optionally filter based on the sort key.使用Query时,您必须指定分区键,并且可以选择根据排序键进行过滤。 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.要从基于不同分区键的二级索引中检索数据,您需要针对这些键的单独值发出多个Query操作,这里没有批处理。

You can use PartiQL with WHERE IN clause for that:您可以将 PartiQL 与WHERE IN子句一起使用:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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