[英]Python AWS dynamoDB: how can I query elements with a filter on not primary column?
我使用 dynamoDB 為應用存儲數據。
實際上:我正在從我的 dynamodb 加載所有數據(使用.scan()
)然后我在本地過濾數據。
問題:加載值需要太多時間。
解決方案:僅加載過濾后的數據。 我無法使用這樣的查詢:
# Use the Table resource to query for all songs by artist Arturus Ardvarkian
response = table.query(
KeyConditionExpression=Key('artist').eq('Arturus Ardvarkian')
)
print(response['Items'])
他們總是說botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element: mail
您可以在 DynamoDB 表中創建本地或全局二級索引。 從您的角度來看,這就像有不同的表定義(即表鍵),但附加到相同的數據。
這樣您就可以使用查詢而不是過濾掃描結果。
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html
確切的選擇(LSI 與 GSI)取決於您的用例,您可以在此處找到兩者之間的比較:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SecondaryIndexes.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.