4
votes

I am trying to query a dynamodb table. When I'm using the begins with operator I'm getting the following error.

{u'Message': u'All queries must have a condition on the hash key, and it must be of type EQ', u'__type': u'com.amazon.coral.validate#ValidationException'}

result_set = tb_places.query_2(
    place_name__beginswith="ame",
)

Here place_name is a Global Secondary Index

1
If place_name is the hash_key, a query won't work like this. You also didn't specify the index name (index='DateJoinedIndex')mkobit

1 Answers

14
votes

Regardless if you are querying a table or index, the only operator that can be applied to a Hash Key attribute is the EQ. Alternatively, you could use BEGINS_WITH on a Range Key.

For a query on a table, you can have conditions only on the table primary key attributes. You must provide the hash key attribute name and value as an EQ condition. You can optionally provide a second condition, referring to the range key attribute.[...]

For a query on an index, you can have conditions only on the index key attributes. You must provide the index hash attribute name and value as an EQ condition. You can optionally provide a second condition, referring to the index key range attribute.

Source: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html