You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用C# SDK创建CosmosDB空间索引出现非指定类型是否为Bug?

问题原因

你使用的Microsoft.Azure.Cosmos C# SDK中,SpatialPath类的实例在初始化时,SpatialTypes属性默认就会预先填充Point、LineString、Polygon、MultiPolygon四种全部的空间类型。你代码中仅执行了新增Point类型的操作,没有先清空SpatialPath自带的默认类型列表,因此最终提交到服务端的索引配置依然包含全部四种空间类型。

修复方案

在添加你需要的Point类型之前,先清空SpatialPath实例的SpatialTypes列表即可,修改后的代码参考:

// Clear any existing spatial indexes ...
container_properties.IndexingPolicy.SpatialIndexes.Clear();

// Add a spatial index for the geopoint (Point) property ...
spatial_path = new Microsoft.Azure.Cosmos.SpatialPath();
spatial_path.Path = "/geopoint/?";

// 先清空默认填充的所有空间类型
spatial_path.SpatialTypes.Clear();
// 再添加你需要的Point类型
spatial_path.SpatialTypes.Add(Microsoft.Azure.Cosmos.SpatialType.Point);

container_properties.IndexingPolicy.SpatialIndexes.Add(spatial_path);

// Update the container ...
container_response = await m_container.ReplaceContainerAsync(container_properties);

修改后重新提交配置,就只会保留Point类型的空间索引。

内容的提问来源于stack exchange,提问作者bdcoder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 00:48:04