虽然许多功能会自动启用并内置到 Microsoft Fabric 中的 Cosmos DB,但仍有一些地方可以通过配置自定义容器的行为。 本指南将引导您逐步完成在您的 Fabric 数据库中的 Cosmos DB 容器上配置最常见的可自定义设置的步骤。
先决条件
现有Fabric容量
- 如果没有 Fabric 容量, 请启动 Fabric 试用版。
Fabric 中的现有 Cosmos DB 数据库
包含数据的现有容器
- 如果您还没有,请加载示例数据容器。
更新设置
若要修改 Cosmos DB 容器,请在 Fabric 门户中打开容器的 “设置” 部分。 可以自定义生存时间(TTL)、地理空间配置和索引策略的设置。
注释
矢量和全文容器策略、分区键是不可变的,在创建容器后无法更改。 无法在 Fabric 门户中更改容器吞吐量,但可以使用 Cosmos DB SDK 进行修改。 有关详细信息,请参阅 更改吞吐量 。
打开 Fabric 门户(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}")