[英]Dynamodb - query by GSI using python boto3
I`m using python boto3 to work with dynamodb. 我正在使用python boto3与dynamodb一起工作。 I've created a table using the following script:
我使用以下脚本创建了一个表:
cls.table = dynamodb.create_table(
TableName='table-unittest',
KeySchema=[
{
'AttributeName': 'id',
'KeyType': 'HASH',
},
{
'AttributeName': 'user_name',
'KeyType': 'RANGE',
}
],
AttributeDefinitions=[
{
'AttributeName': 'id',
'AttributeType': 'N',
},
{
'AttributeName': 'user_name',
'AttributeType': 'S',
},
{
'AttributeName': 'age',
'AttributeType': 'N',
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 2,
'WriteCapacityUnits': 2,
},
GlobalSecondaryIndexes=[
{
'IndexName': 'age-index',
'KeySchema': [
{
'AttributeName': 'age',
'KeyType': 'HASH',
},
],
'Projection': {
'ProjectionType': 'KEYS_ONLY',
},
'ProvisionedThroughput': {
'ReadCapacityUnits': 2,
'WriteCapacityUnits': 2,
}
},
],
)
But, when querying the table by its age-index
global secondary index, i receive the following message: 但是,当通过
age-index
全局二级索引查询表时,我收到以下消息:
Query condition missed key schema element: age
Here is the params i pass to the boto3 query method: 这是我传递给boto3查询方法的参数:
{
'ConsistentRead': False,
'IndexName': 'age-index',
'QueryFilter': {
'age': {
'ComparisonOperator': 'GT',
'AttributeValueList': [18]
}
},
'TableName': 'table-unittest',
'ScanIndexForward': False,
'KeyConditions': {
'id': {
'ComparisonOperator': 'EQ',
'AttributeValueList': [222]
}
}
} }
you cant query your global secondary index using your table hash key as conditions (id) 您不能使用表哈希键作为条件(id)查询全局二级索引
you only can: 您只能:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.