0

Using CosmosDb and the .NET SDK, I can't seem to get the spatial index set the way I'm telling it.

NOTE: I am not creating any spatial indexes when the collection is created. I am updating it separately.

I am setting it for a single SpatialType of Point, but it still creates a list of all spatial types.

Here's my code:

containerResponse.Resource.IndexingPolicy.IndexingMode = IndexingMode.Consistent;
containerResponse.Resource.IndexingPolicy.SpatialIndexes.Clear();

containerResponse.Resource.IndexingPolicy.Automatic = true;

containerResponse.Resource.IndexingPolicy.SpatialIndexes
    .Add(
        new SpatialPath
        {
            Path = "/*",
            SpatialTypes = { SpatialType.Point }
        }
    );

await Client.GetContainer(database, collection).ReplaceContainerAsync(containerResponse.Resource);

When I check the result in Azure Portal Data Explorer, I see this:

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

I can manually override it in the portal, but I'm trying to automate this.

Any idea what I'm doing wrong?

If it doesn't make any difference, then fine. Maybe someday I'll find another use for all those other spatial indexes, but I still don't know why it's not working.

1 Answer 1

1

This is expected behavior but it's not currently documented. This is being addressed now.

Bottom line these other spatial types will have no impact on cost or performance.

Sign up to request clarification or add additional context in comments.

3 Comments

Is this the same problem for composite indexes using the SDK? Make the changes and nothing shows?
Composite Indexes have an impact if the data inserted is defined within the index.
My bad. Poorly worded question. I was having trouble adding composite indexes using the SDK. Now it’s working. Not sure what the problem was. If it happens again, I’ll post a new question. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.