How to enable geospatial index in cosmosdb during migration? there is no option is showing in feature section of cosmosdb?

Chandra Shekar 0 Reputation points
2024-12-21T05:15:26.48+00:00

I am not able to enable geospatial index in cosmosdb during migration.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,710 questions
{count} votes

1 answer

Sort by: Most helpful
  1. VINODH KUMAR T D 26,141 Reputation points MVP
    2024-12-21T15:21:08.7733333+00:00

    To enable geospatial indexing in Cosmos DB during migration, follow these steps to ensure it's configured correctly, as this option is not always directly visible in the UI:

    1. Understand Geospatial Indexing
    • Geospatial indexing in Azure Cosmos DB is supported for Azure Cosmos DB Core (SQL) API.
    • The feature is applied at the container (collection) level by modifying the indexing policy.
    1. Modify Indexing Policy
    • The geospatial indexing option must be explicitly defined in the indexing policy of the container. You cannot directly enable it during migration through a visible toggle; instead, you need to update the indexing policy either before or after the migration.

    Update the Indexing Policy via Azure Portal:

    Navigate to your Cosmos DB account in the Azure Portal.

    Go to the Data Explorer and find the target container.

    Open the Settings of the container.

    Locate the Indexing Policy section.

    1. Add or update the following in the indexing policy:

      *az cosmosdb sql container update * *--account-name <CosmosDBAccountName> * *--database-name <DatabaseName> * *--name <ContainerName> * --resource-group <ResourceGroupName> * --indexing-policy '{ "indexingMode": "consistent", "automatic": true, "includedPaths": [ { "path": "/", "indexes": [ {"kind": "Range", "dataType": "Number"}, {"kind": "Range", "dataType": "String"}, {"kind": "Spatial", "dataType": "Point"} ] } ], "excludedPaths": [] }'

      Ensure the Spatial index is added for the appropriate data type (e.g., Point). Save the updated policy.

    Update the Indexing Policy via CLI or SDK:

    Use the Azure Cosmos DB SDK or Azure CLI to modify the container’s indexing policy programmatically. Example using Azure CLI:

    az cosmosdb sql container update
    --account-name <CosmosDBAccountName>
    --database-name <DatabaseName>
    --name <ContainerName>
    --resource-group <ResourceGroupName>
    --indexing-policy '{ "indexingMode": "consistent", "automatic": true, "includedPaths": [ { "path": "/*", "indexes": [ {"kind": "Range", "dataType": "Number"}, {"kind": "Range", "dataType": "String"}, {"kind": "Spatial", "dataType": "Point"} ] } ], "excludedPaths": [] }'

    1. Verify Geospatial Data
    • Ensure that your data schema contains geospatial fields, such as those with Point data types. Example:

      {

      "id": "1",
      "location": {
          "type": "Point",
          "coordinates": [-122.084, 37.422]
      }
      

      }

    • Migrate the Data
    • Use Azure Data Migration Tool (DMS) or a custom migration script that supports updating the indexing policy.
    • Confirm that geospatial fields are correctly indexed and queries work as expected.
    1. Test Queries
    • Run geospatial queries (ex: ST_DISTANCE, ST_WITHIN) to ensure indexing is working.

    If the option still does not show in the Azure portal, modifying the indexing policy directly through the Azure CLI, SDK, or REST API as described above is the best alternative.

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.