bdcoder
bdcoder

Reputation: 3781

CosmosDB spatial index creation - bug?

I create a container (using CosmosDB Emulator) and then want to add a spatial index for a Point property that will be present within my documents. I am using the Microsoft.Azure.Cosmos (C#) SDK to create the spatial index, i.e.:

// 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/?";


// Add Point index type ...

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 );

The code above executes successfully. However, when I examine the spatial indexes created via the Emulator, the following is shown:

"spatialIndexes": [
        {
            "path": "/geopoint/?",
            "types": [
                "Point",
                "LineString",
                "Polygon",
                "MultiPolygon"
            ]
        }

Question - Why are the "LineString", "Polygon" and "MultiPolygon" types shown when the code only specified / added the "Point" type?

Thanks in advance.

Upvotes: 1

Views: 286

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136206

Why are the "LineString", "Polygon" and "MultiPolygon" types shown when the code only specified / added the "Point" type?

This is not a bug in the SDK. It is by design. From Index geospatial data with Azure Cosmos DB documentation page (emphasis mine):

Azure Cosmos DB supports indexing of Points, LineStrings, Polygons, and MultiPolygons. If you index any one of these types, we will automatically index all other types. In other words, if you index Polygons, we'll also index Points, LineStrings, and MultiPolygons. Indexing a new spatial type does not affect the write RU charge or index size unless you have valid GeoJSON data of that type.

Upvotes: 0

Related Questions