DynamoDb "Query key condition not supported"

4.2k Views Asked by At

i have a table and have set up a GSI to do a query. the attribute that i am setting the condition for is of type number. i set the attribute value for the comparison like this: AttributeValue value = new AttributeValue(); value.setN(String.valueOf(3));

i succeed in doing a query where the ComparisonOperator is set to EQ. the correct result is given but none of the other options ( NE | LE | LT | GE | GT | etc) work. they all throw a ValidationException - Query key condition not supported (Service: AmazonDynamoDB; Status Code: 400;...

what am i doing wrong?

much appreciated

1

There are 1 best solutions below

1
On

When you query the GSI with partition key attribute, only equality operator is allowed for the partition key. If you don't know the value of partition key, you need to use scan api.

Query api allows other conditional operators for sort key attribute. However, you can use only equality operator for partition key. Otherwise, you can't use query api.

Filterexpression allows all kind of conditional operators when you use it with non-key attributes.