雖然許多功能會自動啟用並內建至 Microsoft Fabric 中的 Cosmos DB,但仍有一些地方可讓您透過設定自定義容器的行為。 在本指南中,您將逐步解說在 Fabric 資料庫中為 Cosmos DB 中容器設定最常見的可自定義設定步驟。
先決條件
現有的網狀架構容量
- 如果您沒有 Fabric 容量, 請啟動 Fabric 試用版。
Fabric 中現有的 Cosmos DB 資料庫
具有數據的現有容器
- 如果您還沒有範例 數據容器,建議您載入範例數據容器。
更新設定
若要修改 Cosmos DB 容器,請在 Fabric 入口網站中開啟容器 的設定 區塊。 可自訂存活時間(TTL)、地理空間配置及索引政策的設定。
備註
向量與全文容器政策、分割鍵是不可變的,且容器建立後無法更改。 容器吞吐量無法在 Fabric 入口中更改,但可透過 Cosmos DB SDK 進行修改。 詳情請參見 「變更吞吐量 」。
開啟網狀架構入口網站 (https://app.fabric.microsoft.com)。
流覽至現有的 Cosmos DB 資料庫。
選取並展開現有的容器。 然後,選取 [ 設定]。
在 設定 區段中,選取 備援 設定 索引標籤。
生存時間與地理空間配置
編製索引原則
索引 政策 區塊會為你的容器自訂索引。 索引可自定義 Cosmos DB 如何在內部將項目轉換成樹狀結構表示法。 自訂索引政策可以調整容器查詢的效能,或提升資料的寫入效能。
仍在 設定 區域中,選取 編製索引原則 標籤。
使用新的 JSON 索引編製原則更新編輯器:
{ "indexingMode": "consistent", "automatic": true, "includedPaths": [ { "path": "/*" } ], "excludedPaths": [ { "path": "/\"_etag\"/?" } ] }備註
根據預設,Fabric 中的 Cosmos DB 會自動為容器中的所有項目編制每個屬性的索引。 此範例中說明的原則是新容器的默認原則。
選取 [儲存 ] 以儲存您的變更。
小提示
如需編製索引的詳細資訊,請參閱 編製索引原則。
吞吐量變更
容器的吞吐量可以透過 Cosmos DB SDK 來完成。 這可以用 Fabric 裡的筆記本輕鬆完成。 以下是簡化的範例。 完整的範例筆記本請參考 Fabric 中的 Cosmos DB 管理作業。 這會提供一本完整的範例筆記本,你可以匯入工作區使用。
# Get the current throughput on the created container and increase it by 1000 RU/s
throughput_properties = await CONTAINER.get_throughput()
autoscale_throughput = throughput_properties.auto_scale_max_throughput
print(print(f"Autoscale throughput: {autoscale_throughput}"))
new_throughput = autoscale_throughput + 1000
await CONTAINER.replace_throughput(ThroughputProperties(auto_scale_max_throughput=new_throughput))
# Verify the updated throughput
updated_throughput_properties = await CONTAINER.get_throughput()
print(f"Verified updated autoscale throughput: {updated_throughput_properties.auto_scale_max_throughput}")