[英]OR condition in filter expression for dynamo db
我有一個用例,我需要使用dynamo db查詢表達式以編程方式查詢dynamo db。 例如,假設A和B有兩個屬性,我想要一個過濾表達式,如(A='Test' OR A ='Test1') and B='test2'
。
我搜索了相關的但沒有找到有用的資源。 我是dynamo db的新手。
多數民眾贊成你如何在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);
如果你的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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.