[英]Dynamodb GSI containing boolean
I have a dynamodb table of events that have specified start and end times.我有一个 dynamodb 事件表,其中包含指定的开始和结束时间。 These events can be happening in realtime, in which case, the end timestamp is not yet written.
这些事件可以实时发生,在这种情况下,结束时间戳尚未写入。
I have setup a global secondary index with the sort key being the binary field, active
.我已经设置了一个全局二级索引,其中排序键是二进制字段
active
。 When I try and update a record to set this to true, I get the error:当我尝试更新记录以将其设置为 true 时,出现错误:
Expected: B Actual: BOOL
The python code for this is: python 代码是:
table.update_item(
Key={
'fingerprint': item['fingerprint'],
'startedtimestamp': item['startedtimestamp']
},
UpdateExpression="SET #active :active, resolvedtimestamp :resolvedtimestamp",
ExpressionAttributeNames : {
'#active' : 'active',
'#resolvedtimestamp' : 'resolvedtimestamp'
},
ExpressionAttributeValues={
':active': False, ':resolvedtimestamp': resolvedtimestamp},
)
I have also been reading elsewhere about using a sparse index instead.我也一直在其他地方阅读有关使用稀疏索引的信息。 In this case though, if the index was just the
resolvedtimestamp
, would it be possible to query for the active records (eg resolvedtimestamp
is not set)?但是在这种情况下,如果索引只是
resolvedtimestamp
,是否可以查询活动记录(例如未设置resolvedtimestamp
)? Otherwise, what other optimizations can I do to the table and indices to be able to query for active records?否则,我可以对表和索引做哪些其他优化,以便能够查询活动记录?
I have setup a global secondary index with the sort key being the binary field,
active
我已经设置了一个全局二级索引,其中排序键是二进制字段,
active
active
is a boolean not a binary field and that is why you receive the exception. active
是 boolean 而不是二进制字段,这就是您收到异常的原因。 Also, it's not possible to use boolean as part of a primary key, it must be string, number or binary.此外,不能将 boolean 用作主键的一部分,它必须是字符串、数字或二进制。
If you are only interested in active records, then set active = 'True'
only when true, do not set it to false.如果您只对活动记录感兴趣,那么只在为真时设置
active = 'True'
,不要将其设置为假。 If false, delete the attribute from the item.如果为 false,则从项目中删除该属性。 This will give you a sparse index.
这会给你一个稀疏索引。
table.update_item(
Key={
'fingerprint': item['fingerprint'],
'startedtimestamp': item['startedtimestamp']
},
UpdateExpression="SET #active = :active, resolvedtimestamp = :resolvedtimestamp",
ExpressionAttributeNames : {
'#active' : 'active',
'#resolvedtimestamp' : 'resolvedtimestamp'
},
ExpressionAttributeValues={
':active': 'True',
':resolvedtimestamp': resolvedtimestamp},
)
Please update your Update Expression with.请更新您的更新表达式。
UpdateExpression="SET #active = :active, resolvedtimestamp = :resolvedtimestamp",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.