DynamoDB Java过滤器列表-示例 [英] DynamoDB java filter list - example
本文介绍了DynamoDB Java过滤器列表-示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前的架构如下:
- userId :hashKey
- 日期:范围键
- 标签:字符串列表
- userId: hashKey
- date: range-key
- label: List of strings
我正在尝试运行一个查询,该查询获取具有哈希键,范围键和一个或多个特定标签字符串的项目。例如:user(123),since(1/13/2015),label(重要,有趣)
I'm trying to run a query that gets items with hash-key, range-key and one or more specific label string. for example: user(123), since(1/13/2015), label (important,fun)
根据我的理解,DynamoDB最多可以给出2个索引(全局或本地),所以我需要使用过滤器。
Based on my understanding, DynamoDB can give max of 2 indexes (global or local) so I need to use filters.
仅当标签完全相同时才运行以下代码,而不是列表中的一项。
Running the following code works only when the labels are exactly the same, not one item in a list.
List <String>labels=new ArrayList<String>();
labels.add("fun");
labels.add("important");
Map<String,AttributeValue> expressionAttributeValues=new HashMap<>();
expressionAttributeValues.put(":pr", new AttributeValue().withSS(labels));
queryRequest.withFilterExpression("labels IN (:pr)");
queryRequest.withExpressionAttributeValues(expressionAttributeValues);
能否举个例子,如何过滤列表属性(withSS)?
Can you give an example how to filter a list attribute (withSS)?
推荐答案
请尝试以下语法。
expressionAttributeValues.put(":pr", new AttributeValue().withS(labels));
queryRequest.withFilterExpression("contains(labels, :pr"));
这篇关于DynamoDB Java过滤器列表-示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文