2017-04-26 58 views
0

我的表架构是迪纳摩QuerySpec与GSI

virtual_key(hashKey) actual_key(GSI)

现在我想根据我actual_key像下面

final QuerySpec spec = new QuerySpec() 
     .withHashKey("actual_key", "1234"); 
    final Index index = table.getIndex("actual_key"); 
    final ItemCollection<QueryOutcome> result = index.query(spec); 

我要查询索引很确定,项目'actual_key:1234'在我的表中存在,但我得到一个空的结果集。 注:我甚至尝试

final QuerySpec spec = new QuerySpec() 
    .withKeyConditionExpression("actual_key = :v_key") 
     .withValueMap(new ValueMap().withString(":v_key","1234")); 

我不明白的地方,我犯了一个错误?和 我们可以使用'.withHashKey'作为GSI吗?

+0

你能显示你的数据吗?截图还是什么?并描述表格输出。 – notionquest

回答

0
QuerySpec spec = new QuerySpec() 
    .withKeyConditionExpression("actual_key = :actualKey") 
    .withValueMap(new ValueMap() 
     .withString(":actualKey","1234")); 

ItemCollection<QueryOutcome> items = index.query(spec); 
Iterator<Item> iter = items.iterator(); 
while (iter.hasNext()) { 
    System.out.println(iter.next().toJSONPretty()); 
} 
+0

正如我所说我已经尝试过这一点。但没有用:( – Deeps