问题
I have written some python code, I want to query dynamoDB data by sort key. I remember I can use follow-up code successful:
table.query(KeyConditionExpression=Key('event_status').eq(event_status))
My table structure column
primary key:event_id
sort key: event_status
回答1:
You have to create a global secondary index (GSI) for the sort key in order to query on it alone.
回答2:
The scan API should be used if you would like to get data from DynamoDB without using Hash Key attribute value.
Example:-
fe = Attr('event_status').eq("new");
response = table.scan(
FilterExpression=fe
)
for i in response['Items']:
print(json.dumps(i, cls=DecimalEncoder))
while 'LastEvaluatedKey' in response:
response = table.scan(
FilterExpression=fe,
ExclusiveStartKey=response['LastEvaluatedKey']
)
for i in response['Items']:
print(json.dumps(i, cls=DecimalEncoder))
来源:https://stackoverflow.com/questions/42371411/dynamodb-how-to-query-by-sort-key-only