I'm trying to define indexing on few properties in Comos but I'm a little bit confused about automatic indexing. As per the Cosmos DB documentation:
By default, Azure Cosmos DB automatically indexes every property for all items in your container without having to define any schema or configure secondary indexes.
Also, refer to this:
In some situations, you may want to override this automatic behavior to better suit your requirements. You can customize a container's indexing policy by setting its indexing mode, and include or exclude property paths.
What I understand from the above points is that unless we define our custom indexing policy the automatic indexing is set to true
(which makes sense). If however, we defined our own include and exclude paths
for indexing else it should be false
.
It would probably mean that if I define the container properties as below, the Indexing Policy
Automatic
property should be set to false
on Cosmos DB.
using Microsoft.Azure.Cosmos; //Azure Cosmos SDK v3.3.1
.
.
var containerProperties = new ContainerProperties
{
Id = "SOME_CONTAINER_NAME",
PartitionKeyPath = "/MY_PARTITION_KEY",
};
containerProperties.IndexingPolicy.IncludedPaths.Add(new IncludedPath {Path = "/\"{MY_PARTITION_KEY}\"/?"});
containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath {Path = "/*"});
However, I see that with the above configuration on CosmosDb indexing being defined with automatic
set to true
.
Are Automatic
property and IncludedPaths
, ExcludedPaths
properties in IndexingPolicy
class
unrelated? If so, what does automatic
property means when we have defined IncludedPaths
and ExcludedPaths
on indexing policy?
Edit 1
It becomes a little bit more tricky and confusing. Even after setting Automatic
property to false
the property remains true
in the portal.
That is the below code does not seem to have any effect.
containerProperties.IndexingPolicy.Automatic = false;
Edit 2
Even if I update the automatic
property from the portal settings
, the value does not change. And I also do not receive any error.