fredy
fredy

Reputation: 585

DynamoDB java filter list - example

My current schema is as follow:

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)

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);

Can you give an example how to filter a list attribute (withSS)?

Upvotes: 2

Views: 6965

Answers (2)

SRI PREM
SRI PREM

Reputation: 49

If you still haven't found a solution, one more suggestion. Pass the List<String> as comma-separated String values inside IN Clause, that will work.

Upvotes: -1

notionquest
notionquest

Reputation: 39186

Please try with the below syntax. It works for me.

expressionAttributeValues.put(":pr", new AttributeValue().withSS(labels));
queryRequest.withFilterExpression("contains(labels, :pr"));

Upvotes: 4

Related Questions