DynamoDB 查询的多个二级索引

PAs*_*nox 1 amazon-web-services python-2.7 amazon-dynamodb boto3

我希望使用我在查询中创建的二级索引来请求我的 DynamoDB 表。

截至目前,对于单个二级索引,我正在做:

response = dynamodb.Table('TABLE').query(
    IndexName='permaname-index',
    KeyConditionExpression=Key('permaname').eq(permaname)
)
Run Code Online (Sandbox Code Playgroud)

我会像这样构建我的 KeyConditionExpression :

KeyConditionExpression=Key('permaname').eq(permaname) & Key('source').eq(source)
Run Code Online (Sandbox Code Playgroud)

我一遍又一遍地阅读这个文档,但我不知道该怎么做:

https://docs.aws.amazon.com/fr_fr/amazondynamodb/latest/gettingstartedguide/GettingStarted.Python.04.html

https://boto3.readthedocs.io/en/latest/

not*_*est 6

DynamoDB 查询(即查询 API 参数)可以一次从单个资源(即表或 GSI)获取数据。换句话说,您无法在单个查询参数中从多个表或 GSI 检索数据。DynamoDB 查询一次只能引用一个资源。

与可以引用多个表的 RDBMS 不同,DynamoDB 不能同时引用多个表或 GSI(即在单个查询中)。

因此,DynamoDB 有一个功能,可以将主表中的所有属性包含在 GSI 中。ProjectionType在为表创建 GSI 时,您可以将表中的所有属性包含到 GSI 中。

投影类型:全部

GSI 查询示例:-

response = table.query(
    IndexName='Movies_Gsi',
    KeyConditionExpression=Key('title').eq('Movie with nested map') & Key('yearkey').eq(2017)
)
Run Code Online (Sandbox Code Playgroud)