How do I define my indexing policy if I only want to index (the default) "id" in Azure Cosmos Containers? If I do the below, would id be dropped as an index? or would it not index anything except for the default id? I tried looking through documentation but couldn’t find anything explicit about this.
indexing_policy {
indexing_mode = "consistent"
excluded_path {
path = "/*"
}
}
2
Answers
Yes,
/id
is always being indexedSource
So yes, your indexing policy should give you what you are looking for.
Are you partitioning by /id as well and using your container as a key-value store?
If so then you can turn off indexing altogether because you will not need (or want) to use queries to do single document operations. Point operations using the
id
andpartition key
values passed into those operations do not require users to define an index at all.Update:
Additional comments regarding your design using /id as your partition key but then doing range queries deviceId & a unix time stamp.
In IoT scenarios (which this sounds like) using /id as your partition key with a random GUID (which it also sounds like you are also doing) will not scale. Additionally, the fact that you are actually going to perform queries across your data requires you define an index. My answer ONLY applies if you NEVER run queries, only use point CRUD operations.
The challenge you may face is, as your container initially grows beyond 10K RU/s or 50GB of storage, your container will do a partition split and redistribute your data across both. As that continues and more physical partitions get added and your data distributed among them, your queries will get increasingly slower and more expensive. The design will fundamentally not scale, which is basically the opposite of why you would use this type of database (infinite scale with low latency)
A more typical design for an IoT solution would look like this.
c.deviceId == @deviceIdValue
. Depending on the query, indexes should be defined on one or more properties with optional composite indexes where you have range expressions and/or order by’s on other properties. (PS: you cannot do range filters across partition keys).The caveat in all this is you need to measure to understand whether you need any secondary containers. If your workload is very small, then you don’t need to do any of this. But as it grows, these patterns are designed to help with scalability.
Sample Minimum Indexing Policy to use TTL
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [ ],
"excludedPaths": [
{
"path": "/*"
}
] }