java - how to query dynamodb with LSI and mapper -
i trying load info dynamo db table using lsi , dynamodb mapper class. assume have following code
conisder 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 piece of code retrieve info using lsi , 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(); // code }
[edit] right way query lsi mapper? if not better way fetch data table using lsi , dynamodbmapper? (in terms of performance)
i found https://java.awsblog.com/post/tx3gyzevgo924k4/the-dynamodbmapper-local-secondary-indexes-and-you 2013 link. not able find latest documentation on querying lsi , mapper.
note in code have given, haven't set range key @ all. use queryexpression.setrangekeyconditions() so.
here code sample:
map<string, condition> rangekeyconditions = new hashmap<>(); rangekeyconditions.put("lastname", new condition() .withcomparisonoperator(comparisonoperator.eq) .withattributevaluelist(new attributevalue().withs("someone"))); queryexpression.setrangekeyconditions(rangekeyconditions);`
[update]:
it not sufficient (nor necessary) set range key value ("someone") in object (obj), since object used setting hashkey. have @ examples here
Comments
Post a Comment