Filipa
Filipa

Reputation: 61

I want to add indexes in cosmodb

I want to add indexes in the containers.

So the first thing that I did was to put this code in the bicep and I run:

resource AzureCosmosDatabasesContainers 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-05-15' = [for (azureCosmos, index) in XXXXXXXXXXXXXXXX[environmentCode]: {
  name: '${azureCosmos.account}/${azureCosmos.database}/${azureCosmos.name}'
  properties: {
    resource: {
      id: azureCosmos.name
      indexingPolicy: {
        indexingMode: 'consistent'
        automatic: true
        includedPaths: [
          {
            path: '/*'
            indexes: [
                      {
                      kind: 'Range'
                      dataType: 'Number'
                      precision: -1
                      }
                      {
                      kind: 'Range'
                      dataType: 'String'
                      precision: -1
                      }
                    ]
          }
        ]
      }
       partitionKey: {
        paths: [
          '/_partitionKey'
        ]
        kind: 'Hash'
        version: 2
      }
      conflictResolutionPolicy: {
        mode: 'LastWriterWins'
        conflictResolutionPath: '/_ts'
      }
    }
  }
  dependsOn: [
    AzureCosmosDatabases
  ]
}]

But what happens was that the indexes don't appear. enter image description here

The second thing that I did was to go to the Azure portal - Opened a cosmodb - Opened the Data Explorer pane - select the container that I want to add indexes - Added this code :

"indexes": [
   {
   "kind": "Range",
   "dataType": "Number",
    "precision": -1
   },
   {
   "kind": "Range",
   "dataType": "String",
   "precision": -1
    }
]

enter image description here

And finally, saved. enter image description here

What happens is that I save and it's ok but when I open it again the configuration disappears.

Can anyone help me?

Upvotes: 0

Views: 683

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136196

If you are wondering about not able to see kind, dataType and precision attributes in your indexing policy after it is saved, then it is expected behavior.

From this link:

This indexing policy is equivalent to the one below which manually sets kind, dataType, and precision to their default values. These properties are no longer necessary to explicitly set and you should omit them from your indexing policy entirely (as shown in above example). If you try to set these properties, they'll be automatically removed from your indexing policy.

Upvotes: 2

Related Questions