ValidationException: Query condition missed key schema element
TL;DR — Your KeyConditionExpression must include an equality (=) on the partition key. If you're querying by a non-key attribute, you need a Query on a GSI/LSI that has that attribute as its key — or a Scan with a FilterExpression.
What it means
The full message is usually:
ValidationException: Query condition missed key schema element: pkThe name after the colon is your table's partition-key attribute, so it varies.
Query only works against a key. DynamoDB is telling you the KeyConditionExpression either omits the partition key entirely, or names an attribute that isn't the partition/sort key of the table (or of the index you're querying).
Why it happens
- The
KeyConditionExpressionfilters on a regular attribute (e.g.email,status) instead of the partition key. - You're querying the base table but the attribute is only a key on a GSI — you forgot
IndexName. - The partition key is present but with an operator other than
=(the partition key must be an exact match; only the sort key supports<,>,begins_with,between). - A typo in the attribute name so it no longer matches the schema.
How to fix it
- Query on the partition key with
=. Every Query needspk = :pk(using your table's real key name). - Need to query by a non-key attribute? Create a GSI with that attribute as its partition key and pass
IndexName. - Only need occasional access? Use
Scanwith aFilterExpressioninstead ofQuery— but note Scan reads the whole table.
Example
import {DynamoDBClient} from '@aws-sdk/client-dynamodb';
import {DynamoDBDocumentClient, QueryCommand} from '@aws-sdk/lib-dynamodb';
const doc = DynamoDBDocumentClient.from(new DynamoDBClient({}));
// Query the base table by its partition key:
await doc.send(
new QueryCommand({
TableName: 'Orders',
KeyConditionExpression: 'pk = :pk',
ExpressionAttributeValues: {':pk': 'USER#123'}
})
);
// Query by a non-key attribute → use a GSI that keys on it
// ("status" is a DynamoDB reserved word, so alias it with #status):
await doc.send(
new QueryCommand({
TableName: 'Orders',
IndexName: 'byStatus',
KeyConditionExpression: '#status = :s',
ExpressionAttributeNames: {'#status': 'status'},
ExpressionAttributeValues: {':s': 'SHIPPED'}
})
);FAQ
What does "Query condition missed key schema element" mean? Your KeyConditionExpression either omits the partition key entirely or names an attribute that isn't the partition or sort key of the table or index you're querying. Every Query needs an equality condition on the partition key.
How do I query DynamoDB by a non-key attribute?
Create a GSI with that attribute as its partition key and pass IndexName in the Query — or, for occasional access, use a Scan with a FilterExpression, keeping in mind that a Scan reads the whole table.
Reproduce it
A Query whose condition names only the sort key:
await client.send(
new QueryCommand({
TableName: 'orders',
KeyConditionExpression: 'sk = :s',
ExpressionAttributeValues: {':s': {S: 'META'}}
})
);Real output:
ValidationException: Query condition missed key schema element
HTTP 400Every Query must pin exactly one partition key. Wanting to search by sort key alone is the classic sign that the access pattern needs a GSI rather than a Query — or, if you genuinely must read every partition, a Scan.
Related errors
- The provided key element does not match the schema
- ValidationException (overview)
- Code example: Query in Node.js · in Python (boto3) — a KeyConditionExpression done right.
- Learn: Query vs Scan · Key condition expressions
References
- Query — Amazon DynamoDB API Reference
- Reserved words in DynamoDB — Amazon DynamoDB Developer Guide
- Using Global Secondary Indexes in DynamoDB — Amazon DynamoDB Developer Guide
Last verified 2026-07-13 against the official AWS documentation linked above.
Reproduced 2026-07-26 against DynamoDB Local 2.x with AWS SDK for JavaScript v3.1095.0 — the output above is verbatim.