java - How to do Query in DynamoDB on the basis of HashKey and range Key? -


i new dynamodb stuff. want know how can query on table in dynamodb hashkey , rangekey.

let's table testtable , it's schema this:

1.id (hk of type string) 2 date (rk of type string ) 3 name (attribute of type string) 

now if want query on table on basis of hashkey id here, make query :

let's query items having id ="123".

testtable testtable = new testtable(); testtable.setid("123");  dynamodbqueryexpression<testtable> queryexpression = new dynamodbqueryexpression<testtable>()                                                                 .withhashkeyvalues(testtable)                                                                 .withconsistentread(false); 

now want items having id ="123" , date ="1234".

how can query thing in dynamodb

i using java programming language.

i wrote article dynamodb queries , indexing using aws java sdk time ago: http://labs.journwe.com/2013/12/15/dynamodb-secondary-indexes/

in case, should work (see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/javaqueryscanormmodelexample.html):

amazondynamodbclient client = new amazondynamodbclient(new profilecredentialsprovider()); dynamodbmapper mapper = new dynamodbmapper(client);  string hashkey = "123"; long twoweeksagomilli = (new date()).gettime() - (15l*24l*60l*60l*1000l); date twoweeksago = new date(); twoweeksago.settime(twoweeksagomilli); simpledateformat dateformatter = new simpledateformat("yyyy-mm-dd't'hh:mm:ss.sss'z'"); dateformatter.settimezone(timezone.gettimezone("utc")); string twoweeksagostr = dateformatter.format(twoweeksago);             condition rangekeycondition = new condition()         .withcomparisonoperator(comparisonoperator.gt.tostring())         .withattributevaluelist(new attributevalue().withs(twoweeksagostr.tostring()));  reply replykey = new reply(); replykey.setid(hashkey);  dynamodbqueryexpression<reply> queryexpression = new dynamodbqueryexpression<reply>()         .withhashkeyvalues(replykey)         .withrangekeycondition("replydatetime", rangekeycondition);  list<reply> latestreplies = mapper.query(reply.class, queryexpression); 

check out java object persistence model section of dynamodb docs more info.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -