使用具有嵌套属性的ScanFilter扫描AWS DynamoDB

时间:2019-06-06 12:13:14

标签: amazon-web-services amazon-dynamodb aws-sdk aws-sdk-java-2.0

我正在尝试扫描dynamodb,但我的扫描在根属性上工作正常,但在嵌套属性下却无法工作。我的代码库是:

String workingProperty = "name"
String notWorkingProperty1 = "name.firstName"
String notWorkingProperty2 = "#name.firstName"
String notWorkingProperty3 = "#name.#firstName"

private Table table;
public List<Item> getAllFilteredItems() {

    ScanFilter scanFilter = new ScanFilter(propertyToLookFor).exists();
    StreamSupport.stream(table.scan(scanFilter).spliterator(), false)
                .collect(Collectors.toList());
}

我的JSON是:

{
  "name": {
    "firstName": "Manish"
  }
}

1 个答案:

答案 0 :(得分:2)

扫描过滤器是旧版,您应该尝试使用Filter Expression而不是attribute_exists operator

尝试类似的操作(您可以删除withNameMapwithValueMap,但尚未测试)

ScanSpec scanSpec = new ScanSpec().withFilterExpression("attribute_exists(name.firstName)").withNameMap(new NameMap()).withValueMap(new ValueMap());

results = table.scan(scanSpec)