Cosmos DB 中的自动索引

Automatic indexing in Comos DB

我正在尝试为 Comos 中的几个属性定义索引,但我对自动索引有点困惑。根据 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.

另请参考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.

我从以上几点了解到,除非我们定义自定义索引策略,否则自动索引设置为 true(这是有道理的)。但是,如果我们定义了自己的包含和排除 paths 用于索引,否则它应该是 false.

这可能意味着如果我如下定义容器属性,则 Indexing Policy Automatic 属性 应该在 Cosmos DB 上设置为 false

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 = "/*"});

但是,我看到 CosmosDb 索引的上述配置被定义为 automatic 设置为 true

Automatic 属性 和 IncludedPaths, ExcludedPaths IndexingPolicy class 中的属性是否无关?如果是这样,当我们在索引策略上定义了 IncludedPathsExcludedPaths 时,automatic 属性 意味着什么?

编辑 1

它变得有点棘手和混乱。即使在将 Automatic 属性 设置为 false 之后,属性 仍然在门户中 true

也就是下面的代码好像没有任何作用。

containerProperties.IndexingPolicy.Automatic = false;

编辑 2

即使我从门户 settings 更新 automatic 属性,值也不会改变。而且我也没有收到任何错误。

我来自 CosmosDB 工程团队。 "automatic" 属性 和 Included/Excluded 路径无关。

"automatic" 属性 现在已被大多数容器弃用。它可用于将集合水平隔离为两组文档 - 一组是二级索引的,另一组不是,通过覆盖每个文档级别的索引指令。除了缺乏具体的商业价值外,将自动 属性 设置为 false 还会根据查询是否使用索引(例如,与扫描相对)导致查询结果不一致。所以我们现在弃用了 属性(它不能设置为 false)。

我们一般所说的"automatic indexing"就是你容器中所有文档的所有路径默认都被索引了。这可以通过默认索引策略在 IncludedPaths 部分中包含 /*('root' 路径下的所有内容)这一事实看出。希望这有帮助。