Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
This feature is in preview.
Indexing in Cosmos DB is designed to deliver fast and flexible query performance, no matter how your data evolves. In this guide, you modify the indexing policy for a container using the Fabric portal or an Azure SDK.
Prerequisites
An existing Fabric capacity
- If you don't have Fabric capacity, start a Fabric trial.
An existing Cosmos DB database in Fabric
- If you don't have one already, create a new Cosmos DB database in Fabric.
An existing container with data
- If you don't have one already, we suggest that you load the sample data container.
- Python 3.12 or later
- Node.js 22 or later
- .NET SDK 9.0 or later
Set using the Fabric portal
First, use the Fabric portal to set the indexing policy for a container
Open the Fabric portal (https://app.fabric.microsoft.com).
Navigate to your existing Cosmos DB database.
Select and expand your existing container. Then, select Settings.
In the Settings section, select the Indexing Policy tab.
In the editor, update the setting to a new value. For example, you can set the indexing policy to only index the
name
andcategory
properties for items in the container using this policy.{ "indexingMode": "consistent", "automatic": true, "includedPaths": [ { "path": "/name/?" }, { "path": "/category/?" } ], "excludedPaths": [ { "path": "/*" } ] }
Set using the Azure SDK
Finally, use the Azure SDK to set the indexing policy for a container.
database = client.get_database_client("<database-name>")
container = database.get_container_client("<container-name>")
# Create policy that only indexes specific paths
indexing_policy = {
"indexingMode": "consistent",
"automatic": True,
"includedPaths": [
{
"path": "/name/?"
},
{
"path": "/category/?"
}
],
"excludedPaths": [
{
"path": "/*"
}
]
}
# Create policy that only indexes specific paths
database.replace_container(container, partition_key=PartitionKey(path='/<partition-key-path>'), indexing_policy=indexing_policy)
const container: Container = client.database('<database-name>').container('<container-name>');
const { resource: containerProperties } = await container.read();
// Create policy that only indexes specific paths
containerProperties['indexingPolicy'] = {
indexingMode: 'consistent',
automatic: true,
includedPaths: [
{
path: '/name/?'
},
{
path: '/category/?'
}
],
excludedPaths: [
{
path: '/*'
}
]
}
await container.replace(containerProperties);
Container container = client
.GetDatabase("<database-name>")
.GetContainer("<container-name>");
ContainerProperties properties = await container.ReadContainerAsync();
// Create policy that only indexes specific paths
IndexingPolicy indexingPolicy = new()
{
IndexingMode = IndexingMode.Consistent,
Automatic = true
};
indexingPolicy.ExcludedPaths.Add(
new ExcludedPath{ Path = "/*" }
);
indexingPolicy.IncludedPaths.Add(
new IncludedPath { Path = "/name/?" }
);
indexingPolicy.IncludedPaths.Add(
new IncludedPath { Path = "/category/?" }
);
properties.IndexingPolicy = indexingPolicy;
await container.ReplaceContainerAsync(properties);