我正在尝试使用HashKey(Id),SortKey(时间戳)和全局二级索引(requestId)搜索数据,但没有获得正确的结果。
public List<EventLogEntity> getOndemandRequestDetails(String vin, String requestId) {
LOGGER.debug("processing OndemandRequestDetails based on request id");
PaginatedQueryList<EventLogEntity> paginatedResult = null;
String id = vin + UNDERSCORE + GATEWAY_ON_DEMAND_REQUEST;
Map<String, AttributeValue> eav = new HashMap<>();
eav.put(":val1", new AttributeValue().withS(id));
eav.put(":val2", new AttributeValue().withS(requestId));
DynamoDBQueryExpression<EventLogEntity> queryExpression = new DynamoDBQueryExpression<>();
queryExpression.withKeyConditionExpression("id = :val1").withFilterExpression("requestId = :val2")
.withExpressionAttributeValues(eav).withConsistentRead(false);
paginatedResult = dynamoDBMapper.query(EventLogEntity.class, queryExpression);
return paginatedResult;
}
我缺少什么?
答案 0 :(得分:1)
请在查询表达式中设置索引名称。
如果未设置索引名称,则表示您正在查询实际表而不是GSI。
queryExpression.withKeyConditionExpression("id = :val1").withFilterExpression("requestId = :val2")
.withExpressionAttributeValues(eav).withConsistentRead(false)
.withIndexName("YourGSIIndexName");