dynamo db的过滤器表达式中的OR条件

Sum*_*ati 5 query-expressions amazon-web-services amazon-dynamodb

我有一个用例,需要使用dynamo db查询表达式以编程方式查询dynamo db。假设A和B有两个属性,我想要一个类似的过滤器表达式(A='Test' OR A ='Test1') and B='test2'

我搜索与此相关,但找不到有用的资源。我是dynamo db的新手。

git*_*agi 12

这就是你在java中的做法

Table table = dynamoDB.getTable(tableName);
QuerySpec spec = new QuerySpec()
   // .withKeyConditionExpression("partitionKey = :id and sortKey > :range") // In case filter expression is on key attributes
    .withFilterExpression("(A = :a1 or A = :a2) and B = :b")
    .withValueMap(new ValueMap()
        //.withString(":id", "Partition key value")
        //.withString(":range", 100)
        .withString(":a1", "Test")
        .withString(":a2", "Test1")
        .withString(":b", "test2"))
   // .withConsistentRead(true);

ItemCollection<QueryOutcome> items = table.query(spec);
Run Code Online (Sandbox Code Playgroud)

如果你的 A 和 B 是关键属性,你在 KeyConditionExpression 中指定它们,否则一切都在 FilterExpression 中。

主要区别在于,顾名思义,关键表达式应用于关键属性,并且由于它是您收取的费用,因此获取记录,而过滤器表达式是免费的,并在获取这些记录后应用,以返回您只匹配过滤条件记录的内容。

要了解更多信息,请阅读 http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#FilteringResults

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ExpressionPlaceholders.html