英文:
How can I store data on DynamoDB to allow keywords queries?
问题
我有一组关于餐厅的数据,其中包含关键词。(假设每个项目有50个关键词的列表。)
我应该如何设计数据库,以便可以针对关键词进行查询?
英文:
I have a set of data I want to store about restaurants that contains keywords. (Let's say a list of 50 keywords per item.)
How should I architect the database so I can make queries on keywords?
答案1
得分: 1
您选择了不适合这项工作的工具。DynamoDB并未针对搜索进行优化,而您的需求基本上是要进行搜索。查询是基于定义了服务器位置的 PK 进行的。
您可能可以为每个关键字创建一个 GSI,以便根据这些关键字进行查询。但请不要这样做。这是一种巧妙的方法,不具备可伸缩性,而且您将支付更多的存储费用。
对于这种情况,通常的解决方案是数据复制,最好使用 ElasticSearch。DynamoDB 仍然是您的主要数据存储,但数据会被复制到 ElasticSearch,以便您可以基于关键字进行搜索。
使用 DynamoDB 流和 Lambda 函数可以最轻松地实现数据复制。
英文:
You are choosing the wrong tool for the job. Dynamodb is not optimized for search and that's basically what you want to do. Queries are based on PK that define server location.
You could possibly create a GSI for each keyword so you can query based on those. But don't do that. It's hacky, not scalable and you'd pay for storage 50x more.
The usual solution for such case is replication of data, probably best to ElasticSearch. DynamoDB stays as your main datastore but the data is replicated do ElasticSearch that you can use to search over keywords.
Replication is easiest achieved using Lambda function with DynamoDB streams
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论