4

Basically, I have a table with two indexes that I'm trying to query and filter. The querying part works for the Table and the index but the problem happens when I try to filter:

ValidationException: Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {QueryFilter} Expression parameters: {KeyConditionExpression}

Here are the params passed to docClient.query():

{
  TableName: 'MyTable',
  Limit: 15,
  ScanIndexForward: false,
  IndexName: 'user-date-index',
  KeyConditionExpression: '#user = :yyyy',
  ExpressionAttributeNames: { '#user': 'user' },
  ExpressionAttributeValues: { ':yyyy': 'the_user_id' },
  QueryFilter: { status: { AttributeValueList: [Array], ComparisonOperator: 'EQ' } }
}

When I call the query with the same params but without the QueryFilter, I get correct results, but I still need to filter (by status in this case, and I have about 5 other options to filter with).

I've spent a few hours trying different things and the AWS docs are not clear enough and no examples are presented, I've spent a whole day to even get to that point.

user3812411
  • 342
  • 3
  • 17

1 Answers1

3

QueryFilter is considered a Legacy Conditional Parameter. From the previous link:

With the introduction of expression parameters (see Using Expressions in DynamoDB), several older parameters have been deprecated. New applications should not use these legacy parameters, but should use expression parameters instead.

The documentation for QueryFilter recommends using FilterExpression instead.

With FilterExpression, your query may look similar to this:

{
  TableName: 'MyTable',
  Limit: 15,
  ScanIndexForward: false,
  IndexName: 'user-date-index',
  KeyConditionExpression: '#user = :yyyy',
  FilterExpression: '#status = :status',
  ExpressionAttributeNames: { '#user': 'user', '#status': 'status' },
  ExpressionAttributeValues: { ':yyyy': 'the_user_id', ':status': 'STATUS' }
}
Montgomery Watts
  • 3,806
  • 2
  • 10
  • 24