【问题标题】:Updating CosmosDb indexing policy through ARM templates通过 ARM 模板更新 CosmosDb 索引策略
【发布时间】:2020-02-13 21:00:29
【问题描述】:

我正在尝试使用 ARM 模板来更新 cosmos 容器的索引策略。我尝试了 2 种方法,一种是在 ARM 中声明容器时简单地声明索引策略。

{
      "apiVersion": "[variables('cosmosDbApiVersion')]",
      "type": "Microsoft.DocumentDB/databaseAccounts/apis/databases/containers",
      "dependsOn": [ /* resourceId */ ],
      "name": "/* containerName */",
      "properties": {
        "resource": {
          "id": "/* id */",
          "partitionKey": {
            "paths": [
              "/partitionKey"
            ],
            "kind": "Hash"
          },
          "indexes": [
            {
              "indexingMode": "consistent",
              "automatic": true,
              "includedPaths": [
                {
                  "path": "/*",
                  "indexes": [
                    {
                      "kind": "Range",
                      "dataType": "Number",
                      "precision": -1
                    },
                    {
                      "kind": "Hash",
                      "dataType": "String",
                      "precision": 3
                    }
                  ]
                }
              ]
            }
          ],
          "defaultTtl": "[variables('defaultTtlValueToEnableTtl')]"
        }
      }
    },

第二个是使用ARM来部署容器设置:

{
      "apiVersion": "[variables('cosmosDbApiVersion')]",
      "type": "Microsoft.DocumentDB/databaseAccounts/apis/databases/containers/settings",
      "name": "[/* name */",
      "dependsOn": [ " /* container name */" ],
      "properties": {
        "resource": {
          "throughput": "/* some throughput */",
          "indexes": [
            {
              "indexingMode": "consistent",
              "automatic": true,
              "includedPaths": [
                {
                  "path": "/*",
                  "indexes": [
                    {
                      "kind": "Range",
                      "dataType": "Number",
                      "precision": -1
                    },
                    {
                      "kind": "Hash",
                      "dataType": "String",
                      "precision": 3
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    },

这两种技术都不会导致部署失败,但索引策略不会改变。

不胜感激。

【问题讨论】:

    标签: azure-cosmosdb arm-template


    【解决方案1】:

    这是来自模板参考的示例(看起来与您所做的略有不同):

    "resource": {
      "id": "string",
      "indexingPolicy": {
        "automatic": "boolean",
        "indexingMode": "string",
        "includedPaths": [
          {
            "path": "string",
            "indexes": [
              {
                "dataType": "string",
                "precision": "integer",
                "kind": "string"
              }
            ]
          }
        ],
        "excludedPaths": [
          {
            "path": "string"
          }
        ],
        "spatialIndexes": [
          {
            "path": "string",
            "types": [
              "string"
            ]
          }
        ]
      },
      xxx
    }
    

    https://docs.microsoft.com/en-us/azure/templates/microsoft.documentdb/2019-08-01/databaseaccounts/sqldatabases/containers

    【讨论】:

      【解决方案2】:

      对于新容器或在过去一年左右创建的容器,Cosmos 资源提供程序现在会忽略范围和哈希索引类型。 ARM 不验证索引策略,这就是模板会成功部署的原因。

      这些较新的容器不推荐使用哈希索引,因为新索引器中范围索引的性能超过了提供的哈希索引,因此不再需要。

      要创建/修改索引策略,请参阅下面的这篇文章。有多个索引策略示例可以实现从非常简单到更复杂的策略,包括复合索引、空间索引和唯一键。

      https://docs.microsoft.com/en-us/azure/cosmos-db/manage-sql-with-resource-manager#create-resource

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-02
        • 2016-05-05
        • 2021-11-22
        相关资源
        最近更新 更多