The query operation searches for, or filters, data based on primary key values. We can apply the query operation on the table, as well as on secondary indexes that have the composite primary key.
When we apply the query operation on a secondary index, we have to provide a specific value for the partition key using the KeyConditionExpression parameter. Then, the query operation will return all items with the given partition key from the table. If we have defined a sort key, then we have to provide the comparison operator, along with the sort key value in the KeyConditionExpression parameter.
To filter the query result, we can also provide the FilterExpression. If the matching items are not found in the table, the query operation will return the empty result set.
If the composite primary key is the sort key, then the result is always sorted by the sort key values. By default, the sort order is in ascending order; to get the descending order, we have to set the ScanIndexForward parameter to false.
The following code shows the request syntax:
{
"FilterExpression" : "String",
"KeyConditionExpression" : "String",
"ScanIndexForward" : boolean,
"Select" : "String",
"TableName" : "String",
.
.
}