通过ARM模板创建文档集合时,为什么CosmosDB会忽略索引?

时间:2019-07-04 14:44:18

标签: azure azure-cosmosdb azure-resource-manager

给出ARM模板:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "name": "1test2/sql/2test3/3test4",
      "type": "Microsoft.DocumentDB/databaseAccounts/apis/databases/containers",
      "apiVersion": "2015-04-08",
      "properties": {
        "resource": {
          "id": "3test4",
          "indexingPolicy": {
            "indexingMode": "Consistent",
            "includedPaths": [
              {
                  "path": "/definition/property/?",
                  "indexes": [
                    {
                        "kind": "Range",
                        "dataType": "String"
                    }
                ]
              }
          ],
            "excludedPaths": [
            {
                "path": "/*"
            }
        ]
          },
          "partitionKey": {
            "paths": [
              "/definition/id"
            ],
            "kind": "Hash"
          },
        },
        "options": {}
      }
    }
  ]
}

使用PowerShell命令部署到现有CosmosDB数据库时 New-AzureRmResourceGroupDeployment,生成的索引设置为:

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/definition/property/?",
            "indexes": []
        }
    ],
    "excludedPaths": [
        {
            "path": "/*"
        },
        {
            "path": "/\"_etag\"/?"
        }
    ]
}

因此,尽管CosmosDB接受“ includedPaths”,但它忽略了“索引”。我是在做错事还是预期的事?

1 个答案:

答案 0 :(得分:0)

最近对Cosmos DB索引引擎进行了更改,该引擎默认为字符串和数字的范围索引,精度为-1。

ARM模板和文档尚未更新以将其反映为默认值。

如果对索引策略进行非默认更改(例如添加空间索引),则它们将包含在部署的容器中。