英文:
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在通配符搜索方面表现并不好。话虽如此,您有一些可用的选项:
-
您可以在排序键上使用
begins_with
操作符。文档中提到:begins_with (a, substr) — 如果属性 a 的值以特定子字符串开头,则为 true。
-
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:
- 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
- The
contains
operator can be used onFilterExpression
ofscan
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论