通过全局二级索引查询 DynamoDB 表时是否可以指定独占开始键?
我正在使用 aws-java-sdk 版本 1.6.10 并使用QueryExpression
and a DynamoDBMapper
。这是我想做的事情的要点:
MappedItem key = new MappedItem();
item.setIndexedAttribute(attributeValue);
Map<String, AttributeValue> exclusiveStartKey = new HashMap<String, AttributeValue>();
exclusiveStartKey.put(MappedItem.INDEXED_ATTRIBUTE_NAME, new AttributeValue().withS(attributeValue));
exclusiveStartKey.put(MappedItem.TIMESTAMP, new AttributeValue().withN(startTimestamp.toString()));
DynamoDBQueryExpression<MappedItem> queryExpression = new DynamoDBQueryExpression<MappedItem>();
queryExpression.withIndexName(MappedItem.INDEX_NAME);
queryExpression.withConsistentRead(Boolean.FALSE);
queryExpression.withHashKeyValues(key);
queryExpression.setLimit(maxResults * 2);
queryExpression.setExclusiveStartKey(exclusiveStartKey);
这会导致 400 错误,指出指定的开始键无效。 TIMESTAMP 是表索引和全局二级索引的范围键,并且属性值对有效(即表中存在一个项目,其值作为索引的哈希键和范围键传递,并且属性传递作为索引是全局二级索引的哈希键)。
我错过了什么或者这是不可能的吗?
有同样的问题,刚刚得到解决。 :) 回答这个问题已经太晚了,但希望有人会觉得有帮助。
当您查询或扫描带有二级索引和分页的表时,您应该包含主键table和index(作为键),设置时使用最后评估的值(作为属性值)专属启动键.
只是系统输出最后评估的密钥从查询或扫描结果中查看格式。
// let's just assume that we have a table to store details of products
Map<String, AttributeValue> exclusiveStartKey = new HashMap<String, AttributeValue>();
// primary key of the table
exclusiveStartKey.put("productId", new AttributeValue().withS("xxxx"));
exclusiveStartKey.put("produtSize", new AttributeValue().withS("XL"));
// primary key of the index
exclusiveStartKey.put("categoryId", new AttributeValue().withS("xx01"));
exclusiveStartKey.put("subCategoryId", new AttributeValue().withN("1"));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)