简体   繁体   中英

Using contains filter in DynamoDB scan with Java - android

I have aws dynamo db table as follows. 在此处输入图像描述

Now I want to filter it as follows. 在此处输入图像描述

For that I used the following code and i get 0 results in my code.what's wrong with my code.how to fix it?

public ScanResult getAllMemos() {
    ScanRequest scanRequest = new ScanRequest()
            .withTableName(DB_NAME)
            .withFilterExpression("contains(imgName,thumbnail)");
    return util.getAmazonDynamoDBClient(getActivity()).scan(scanRequest);
}

Without filter expression I get all results.

Like was discussed in the comments, you need to create an expression attribute value map with the value of the filter and use this.

Try something like this:

public ScanResult getAllMemos() {

    Map<String, AttributeValue> expressionAttributeValues =
        new HashMap<String, AttributeValue>();
    expressionAttributeValues.put(":val", new AttributeValue().withS("thumbnail"));


    ScanRequest scanRequest = new ScanRequest()
            .withTableName(DB_NAME)
            .withFilterExpression("contains(imgName,:val)")
            .withExpressionAttributeValues(expressionAttributeValues);
    return util.getAmazonDynamoDBClient(getActivity()).scan(scanRequest);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM