如何在DynamoDB上存储数据以允许关键字查询?

huangapple go评论55阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年2月19日 15:58:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75498739.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定