【发布时间】:2016-06-27 16:55:21
【问题描述】:
我正在研究如何将 DynamoDB 和 Cloudsearch 用于我的应用程序。我不了解有关 DynamoDB 的数据库架构的一些事情。考虑到这个架构:
USERS 表
{
"id_users"(PI): <number>,
"created": <string>,
"email" (GSI): <string>,
"firstname": <string>,
"lastname": <string>
"password"(GSI): <string>,
"verified": <boolean>,
"category": <string>,
"colors": <array of strings>, // list of favourite colors of the users (it's an example)
"locale": <string>,
"user_location": { //GeoJSON structure
"type": <string> ex. "location",
"geometry": {
"type": <string> ex. "Point",
"coordinates": [ <number> ex. 125.6, <number> 10.1]
},
"properties": {
"city": <string>,
"country": <string>
}
},
"accounts": [
{
"type": <string>, // ex. "facebook"
"ID": <number>, // ex. 23248323243473743
"access_token": <string>,
"profile_url": <string>
},
{
"type": <string>, // ex. "google"
"ID": <number>, // ex. 23248323243473743
"access_token": <string>,
"profile_url": <string>
}
]
}
它是完整架构的一部分。
所以,
申请路径为myurl.com/users/{:id_users}。
我需要搜索活跃用户和/或在某个范围内或国家/地区以及喜欢一种或多种颜色的人(示例)。我读过我不能在比树的第一个更深的级别内添加索引,并且索引只能是字符串、整数或二进制。另外,Cloudsearch 有更多类型的索引,这对于"colours" 和"verified" 来说是完美的,但是我不能为"coordinates" 添加“深度”索引。
我可以像这样移动第一级的坐标:
location_coordinates: [ <number> ex. 125.6, <number> 10.1],
location_city: <string>,
location_country: <string>,
但它并不“优雅”。我可以为用户位置创建一个外部表,但是我可能会失去文档数据库的所有优势,并且当用户访问配置文件时,我无法通过一次调用来检索/读取所有数据。
我必须修改我的数据库架构?怎么样?
谁在乎优雅,我必须把坐标放在第一层?
"coordinates" 项目没有索引关联,这对性能有负面影响吗?显然,当我使用地理查询搜索用户时。
有什么建议吗?
感谢您的帮助, 亚历山德罗。
【问题讨论】:
-
您需要使用云搜索进行搜索。将您要搜索的所有字段添加为索引参数,还有 latlon 字段可帮助进行地理搜索。检索结果后,您可以通过 id 从 dynamodb 中提取所需的结果。 Dynamo 和 Cloud search 不会自动相互链接,您需要创建一个单独的云搜索域并确保对 dynamoDB 的任何更新都使用 DynamoStreams 和 Lambda 更新为云搜索。
-
不需要深度索引,当 dynamoDB 文档有更新时,dynamo 流将调用 lambda 函数。然后,lambda 函数将转换数据并更新云搜索。您可以将您的位置转换为 latlon 字段并在此处更新云搜索以进行地理搜索。
-
啊,我明白了!感谢您的解释 :) 回答我的问题而不是添加评论,所以我可以将标志标记为“已回答”。
标签: database-design amazon-dynamodb database-schema amazon-cloudsearch nosql