title: How to query records where datetime is greater than X in DynamoDB?
body: <p>I have a table in DynamoDB, and I need to get a list of records (in Java) which are from the last day. They all have a dateTime attribute.</p>
  
  <p>Relevant attributes of the table I'm referring to:
  customerUrl(string, hashkey), dateTime(number, range key), and a few other attributes which aren't relevant</p>
  
  <p>I've already tried setting a Global Secondary Index with a hashkey of dateTime and no range key. This index is named 'performanceIndex'. I then tried to query it as follows:</p>
  
  <pre class="lang-java prettyprint-override"><code>Map&lt;String, AttributeValue&gt; eav = new HashMap&lt;&gt;();
  eav.put(":val1", new AttributeValue().withN(maximumAgeMillis));
  DynamoDBQueryExpression&lt;PingLog&gt; pinglogQuery = new DynamoDBQueryExpression&lt;PingLog&gt;();
  pinglogQuery.setKeyConditionExpression("dateTime &gt; :val1");
  pinglogQuery.setExpressionAttributeValues(eav);
  pinglogQuery.setIndexName("performanceIndex");
  pinglogQuery.setConsistentRead(false);
  List&lt;PingLog&gt; pinglogs = PostDatabaseMapper.getInstance().query(PingLog.class, pinglogQuery);
  </code></pre>
  
  <p>However, the query permanently keeps going and never returns. I added a println statement before and after it, and only the first one actually printed.</p>
  
  <p>Before this query I just did a scan with a filter, and that worked, but now we have so many records (80 million) that a scan takes forever. What should I do? Do I need a different secondary index? Is my query wrong?</p>