如何在DynamoDB中使用LIKE运算符或LIKE条件?

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

How do we use LIKE operator or LIKE condition in DynamoDB?

问题

我想要获取在DynamoDB中类似于'%JUICE%'的数据/记录列表。是否有办法获取这样的数据?

英文:

I would like to get the list of data / records, which are like '%JUICE%' in DynamoDB
is there any way to fetch the data like this?

答案1

得分: 2

DynamoDB在通配符搜索方面表现并不好。话虽如此,您有一些可用的选项:

  1. 您可以在排序键上使用 begins_with 操作符。文档中提到:

    begins_with (a, substr) — 如果属性 a 的值以特定子字符串开头,则为 true。

  2. contains 操作符可以用于数据类型为 STRING、SET 或 LIST 的 scan 操作的 FilterExpression。更多信息请参见文档

请记住,在 scan 操作中使用 contains 关键字将是在 DynamoDB 中实现通配符搜索的一种低效方式。您可能更好地在 DynamoDB 外部实现此类搜索。一种常见的模式是使用 DynamoDB 流和 Elastic Search 来实现更全面的搜索功能。

英文:

DynamoDB is not good at wildcard searches. That being said, you do have a few options available to you:

  1. You can use the begins_with operator with sort keys. The docs say

> begins_with (a, substr)— true if the value of attribute a begins with a particular substring

  1. The contains operator can be used on FilterExpression of scan operations on data types STRING, SET or LIST. More info in the docs.

Keep in mind that using the contains keyword on scan operations will be an inefficient way to implement wildcard searches in DynamoDB. You may be better off implementing this type of search outside of DynamoDB. A common pattern is to use DynamoDB streams and Elastic Search to implement a more full-featured search capability.

huangapple
  • 本文由 发表于 2020年10月20日 22:09:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/64446940.html
匿名

发表评论

匿名网友

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

确定