2
Я использую python boto3 для работы с dynamodb. Я создал таблицу, используя следующий скрипт:Dynamodb - запрос GSI с использованием python boto3
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,
}
},
],
)
Но, при запросе таблицы по ее age-index
глобальным вторичному индексу, я получаю следующее сообщение:
Query condition missed key schema element: age
Вот это PARAMS я перейти к методу boto3 запроса:
{
'ConsistentRead': False,
'IndexName': 'age-index',
'QueryFilter': {
'age': {
'ComparisonOperator': 'GT',
'AttributeValueList': [18]
}
},
'TableName': 'table-unittest',
'ScanIndexForward': False,
'KeyConditions': {
'id': {
'ComparisonOperator': 'EQ',
'AttributeValueList': [222]
}
}
}