One key, every level
A path in the sort key lets one begins_with read any level of a hierarchy.
Why
These weather stations live in one partition, with a sort key that encodes a path: country, then state, then city, joined by a delimiter. Because the partition is stored sorted, every station in a country sits together, and within it every station in a state sits together.
So one begins_with reads any level of the tree. A US# prefix gives a country, US#CA# narrows to a state, and the full path is a single city. No FilterExpression appears anywhere: the hierarchy is in the key, and the key narrows the read before it happens.
Encode a path into the sort key and one begins_with reads any level of the tree, in order, for free.
Try it. Then change it.
Predict what each request will do. Run it, inspect the response, then change a value in the workbench and try again.
begins_with(sk, 'US#') returns every US station and nothing else. A country-level prefix.
Deepen the prefix one segment to US#CA# and the read narrows to three cities. Scanned still equals Returned.
The full path is the whole sort key, so an equals returns a single station.
Built on this
- Folder Tree - What’s inside this folder?
begins_with(sk, 'US#') returns every US station and nothing else. A country-level prefix.
Choose an access pattern above, or build your own request. See what comes back and what it costs.