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).
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).
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.
Here's the code:
Map<String, Condition> 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);
All I get, however, is this error message: com.amazonaws.AmazonServiceException: Query condition missed key schema element: key
Removing the call to withIndexName("event") makes no difference.
I haven't used NoSQL before this week, which may be part of the problem.