I am currently trying to load info from a dynamo DB table using a LSI and dynamoDB mapper class. Assume i have the following code
Conisder this class
class Employee {
@DynamoDBHashKey
public String getID() {
return ID;
}
@DynamoDBRangeKey
public String getFirstName() {
return firstName;
}
@DynamoDBIndexRangeKey(localSecondaryIndexName = "my-lsi")
public String getLastName() {
return lastName;
}
public String getMyotherfield() {
return myotherfield;
}
}
Consider this piece of code to retrieve info using LSI and dynamoDB mapper
Employee obj = new Employee();
obj.setID("221");
obj.setLastName("SOMEONE");
DynamoDBQueryExpression<Employee> queryExpression = new DynamoDBQueryExpression<>();
queryExpression.setHashKeyValues(obj);
queryExpression.setIndexName("my-lsi");
queryExpression.setProjectionExpression("myotherfield");
PaginatedQueryList<Employee> paginatedQueryList = mapper.query(Employee.class, queryExpression);
Iterator<Employee> iterator = paginatedQueryList.iterator();
while (iterator.hasNext()) {
Employee pp = iterator.next();
// some code
}
[EDIT] Is this the right way to query LSI with mapper? If not what is a better way to fetch data from the table using LSI and dynamoDBMapper? (in terms of performance)
i also found this https://java.awsblog.com/post/Tx3GYZEVGO924K4/The-DynamoDBMapper-Local-Secondary-Indexes-and-You but its a 2013 link. I am not able to find latest documentation on querying with LSI and mapper.