php-如何在DynamoDB列表中扫描文本?
作者:互联网
在DynamoDB中,我有一个具有以下结构的表.
动作“字段”包含所有信息(这是我想搜索的字段),而orderId是主键
{
"actions": [
{
"actionDescription": "8f23029def1d6baa4",
"actionTitle": "UNDEFINED_ACTION",
"timestamp": 1533730680,
"user": {
"fullName": "XXXXX",
"userName": "xxxxx@xxxx.xxx",
}
},
{
"actionDescription": "21857e61037bc29ec",
"actionTitle": "UNDEFINED_ACTION",
"timestamp": 1533731788,
"user": {
"fullName": "XXXXX",
"userName": "xxxxx@xxxx.xxx",
}
},
{
"actionDescription": "cf10abd44e24cef56",
"actionTitle": "UNDEFINED_ACTION",
"timestamp": 1533731788,
"user": {
"fullName": "XXXXX",
"userName": "xxxxx@xxxx.xxx",
}
},
{
"actionDescription": "7787fe7a5bf4d22de",
"actionTitle": "UNDEFINED_ACTION",
"timestamp": 1533731789,
"user": {
"fullName": "OOOOOO",
"userName": "ooooo@oooo.ooo",
}
},
{
"actionDescription": "9528c439021f504bf",
"actionTitle": "UNDEFINED_ACTION",
"timestamp": 1533731789,
"user": {
"fullName": "XXXXX",
"userName": "xxxxx@xxxx.xxx",
}
},
{
"actionDescription": "bfba100e0e54934b2",
"actionTitle": "UNDEFINED_ACTION",
"timestamp": 1533731789,
"user": {
"fullName": "XXXXX",
"userName": "xxxxx@xxxx.xxx",
}
},
{
"actionDescription": "f789dc12f1dbe3be2",
"actionTitle": "UNDEFINED_ACTION",
"timestamp": 1533731789,
"user": {
"fullName": "OOOOOO",
"userName": "ooooo@oooo.ooo",
}
},
{
"actionDescription": "4cd6b68dfea7cf8ee",
"actionTitle": "UNDEFINED_ACTION",
"timestamp": 1533731789,
"user": {
"fullName": "XXXXX",
"userName": "xxxxx@xxxx.xxx",
}
},
{
"actionDescription": "1e3a0e95f8e5106d7",
"actionTitle": "UNDEFINED_ACTION",
"timestamp": 1533731790,
"user": {
"fullName": "OOOOOO",
"userName": "ooooo@oooo.ooo",
}
}
],
"orderId": "13aae31"
}
我想做的是使PHP中的扫描项能够通过userName进行搜索.或按操作数组内的任何字段(时间戳,actionTitle等).
波纹管是我尝试使用的许多术语之一,但我无法获得任何结果
$params = [
'TableName' => $this->tableName,
'FilterExpression' => "userName = :searchTerm",
'ExpressionAttributeValues' => [
':searchTerm' => 'ooooo@oooo.ooo',
],
'ReturnConsumedCapacity' => 'TOTAL',
];
$results = $this->dynamoDbClient->scan($params);
您能告诉我我想念的东西吗?
另外,请注意:我不想获取特定的orderId,我想获取所有包含searchTerm的orderId(在这种情况下为userName)
解决方法:
使用此项目模式的最佳选择是自己过滤表项目.也就是说,不使用过滤器表达式扫描表,然后编写自己的代码以过滤结果.不使用过滤器表达式的扫描将消耗相同数量的读取容量单位.
您可以将过滤器表达式设置为类似的内容,但这是不可扩展的,并且仅在操作列表中有固定数量的项目时才有效.
actions[0].user.userName == :searchTerm OR actions[1].user.userName == :searchTerm OR actions[2].user.userName == :searchTerm OR ....
如果您需要复杂的搜索功能,最好使用专用的搜索数据库. AWS为此提供了两项服务,即AWS CloudSearch和AWS ElasticSearch.您可以使用DynamoDB流来使搜索索引保持最新.
如果您打算使用过滤器扫描DynamoDB表,则可以重构结构以在一个集合(或串联字符串)中包含具有所有可搜索信息的其他属性.
{
"actions": [....],
"actionsDescriptions": Set["8f23029def1d6baa4", "21857e61037bc29ec", "cf10abd44e24cef56", "7787fe7a5bf4d22de", "9528c439021f504bf", "bfba100e0e54934b2", "f789dc12f1dbe3be2", "4cd6b68dfea7cf8ee", "1e3a0e95f8e5106d7"],
"actionTitles": Set["UNDEFINED_ACTION"],
"timestamps": Set[1533730680, 1533731788, 1533731789, 1533731790],
"user_fullNames": Set["XXXXX"],
"user_userNames": Set["ooooo@oooo.ooo", "xxxxx@xxxx.xxx"],
"orderId": "13aae31"
}
注意,您必须使用Set(或将所有值连接到字符串中),因为contains函数仅适用于字符串和Set.
然后您可以使用这样的过滤器表达式
contains(user_userNames, :searchTerm)
标签:amazon-dynamodb,dynamodb-queries,php 来源: https://codeday.me/bug/20191108/2009513.html