Skip to content

Commit ec30172

Browse files
committed
python code for index metrics
1 parent 74014d5 commit ec30172

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

articles/cosmos-db/nosql/index-metrics.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ ms.reviewer: jucocchi
1414

1515
Azure Cosmos DB provides indexing metrics to show both utilized indexed paths and recommended indexed paths. You can use the indexing metrics to optimize query performance, especially in cases where you aren't sure how to modify the [indexing policy](../index-policy.md)).
1616

17-
> [!NOTE]
18-
> The indexing metrics are only supported in the .NET SDK (version 3.21.0 or later) and Java SDK (version 4.19.0 or later)
17+
## Supported SDK versions
18+
Indexing metrics are supported in the following SDK versions:
19+
| SDK | Supported versions |
20+
| --- | --- |
21+
| .NET SDK v3 | >= 3.21.0 |
22+
| Java SDK v4 | >= 4.19.0 |
23+
| Python SDK | >= 4.6.0 |
1924

2025
## Enable indexing metrics
2126

@@ -91,6 +96,17 @@ const { resources: resultsIndexMetrics, indexMetrics } = await container.items
9196
.fetchAll();
9297
console.log("IndexMetrics: ", indexMetrics);
9398
```
99+
100+
## [Python SDK](#tab/python)
101+
You can capture index metrics by passing in the populate_index_metrics keyword in query items and then reading the value for "x-ms-cosmos-index-utilization" header from the response. This header is returned only if the query returns some items.
102+
103+
```python
104+
query_items = container.query_items(query="Select * from c",
105+
enable_cross_partition_query=True,
106+
populate_index_metrics=True)
107+
108+
print(container.client_connection.last_response_headers['x-ms-cosmos-index-utilization'])
109+
```
94110
---
95111

96112
### Example output

0 commit comments

Comments
 (0)