gpt4 book ai didi

amazon-dynamodb - 在 FilterExpression 中传递包含的搜索字符串列表

转载 作者:行者123 更新时间:2023-12-02 03:41:57 26 4
gpt4 key购买 nike

是否有任何方法可以在 DynamoDb 中 FilterExpression 的 contains() 方法中传递搜索字符串列表?

如下所示:

search_str = ['value-1', 'value-2', 'value-3']
result = kb_table.scan(
FilterExpression="contains (title, :titleVal)",
ExpressionAttributeValues={ ":titleVal": search_str }
)

现在我只能想到循环遍历列表并多次扫描表(如下面的代码所示),但我认为这会占用大量资源。

for item in search_str:
result += kb_table.scan(
FilterExpression="contains (title, :titleVal)",
ExpressionAttributeValues={ ":titleVal": item }
)

任何建议。

最佳答案

对于上述场景,CONTAINS 应与 OR 条件一起使用。当您将数组作为 CONTAINS 的输入时,DynamoDB 将检查 SET 属性(“SS”、“NS”或“BS”)。它不会查找字符串属性上的子序列。

If the target attribute of the comparison is of type String, then the operator checks for a substring match. If the target attribute of the comparison is of type Binary, then the operator looks for a subsequence of the target that matches the input. If the target attribute of the comparison is a set ("SS", "NS", or "BS"), then the operator evaluates to true if it finds an exact match with any member of the set.

示例:-

movies1 = "MyMovie"
movies2 = "Big New"
fe1 = Attr('title').contains(movies1)
fe2 = Attr('title').contains(movies2)

response = table.scan(
FilterExpression=fe1 or fe2
)

关于amazon-dynamodb - 在 FilterExpression 中传递包含的搜索字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48305197/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com