title: How do I query a secondary index on DynamoDB in Java
body: <p>I am writing an app using which people can request information about specific events.  Because multiple users can request information about the same event, the key for my Request table is username+event (where both of those are strings).</p>
  
  <p>However, in the Java code which supplies that information, I don't want to download data I don't need so, ideally, I'd query on the event (as I don't know the usernames of all the people making the query).</p>
  
  <p>I thought that if I gave the Request table a secondary index, called "event", which the users also filled in (so the hash key (called "key") is username+event, and the event field is just the event string), I'd able to query on the secondary index, and get all the requests for that event.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>Map&lt;String, Condition&gt; keyConditions = new HashMap();
  keyConditions.put("event", new Condition()
                      .withComparisonOperator(EQ)
                      .withAttributeValueList(new AttributeValue().withS(event)));
  QueryRequest one = new QueryRequest()
      .withTableName(REQ_TABLE)
      .withIndexName("event")
      .withKeyConditions(keyConditions);
  QueryResult queryResult = dynamoDB.query(one);
  </code></pre>
  
  <p>All I get, however, is this error message:
  com.amazonaws.AmazonServiceException: Query condition missed key schema element: key</p>
  
  <p>Removing the call to withIndexName("event") makes no difference.</p>
  
  <p>I haven't used NoSQL before this week, which may be part of the problem.</p>