1

我正在尝试从 Azure RM powershell 脚本将 Cosmos DB 帐户的索引策略设置为无,但没有运气。

  $tableProperties = @{
    resource=@{ id=$table; indexingPolicy= @{indexingMode="none"; automatic = "false"; includedPaths = "[]"; excludedPaths = "[]" }  };
     options=@{ Throughput= 500 }
}

  Set-AzureRmResource -ResourceType $tableResourceType `
        -ApiVersion $apiVersion -ResourceGroupName $resourceGroupName `
        -Name $tableResourceName -PropertyObject $tableProperties -Force 

Cosmos DB 中的索引策略节点

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

}

更新:尝试:

$containerResourceType = "Microsoft.DocumentDb/databaseAccounts/tables"
$containerName = $destinationStorageName+"/"+ $table

$containerGet = Get-AzResource -ResourceType $containerResourceType `
    -ApiVersion $apiVersion -ResourceGroupName $resourceGroupName `
    -Name $containerName | Select-Object -ExpandProperty Properties

$containerProperties = @{
    "resource"=@{
        "id"=$containerGet.resource.id; 
        "indexingPolicy"=@{"indexingMode"="none"}
    }
}

Set-AzResource -ResourceType $containerResourceType `
-ApiVersion $apiVersion -ResourceGroupName $resourceGroupName `
-Name $containerName -PropertyObject $containerProperties -Force 

没运气

4

1 回答 1

1

对于索引策略,您只需将 indexingMode 设置为 none。Cosmos 中的子资源也不支持 PATCH,因此对于资源上的任何 PUT,您需要包含已设置的任何其他属性,包括所需的 partitionKey。请参见下面的示例。

更新:此示例使用 AzResource,因为 AzureRM 已被弃用。

$apiVersion="2019-08-01"
$containerResourceType = "Microsoft.DocumentDb/databaseAccounts/sqlDatabases/containers"
$resourceGroupName="myResourceGroup"
$containerName = "mycosmosaccount/myDatabase/myContainer"

$containerGet = Get-AzResource -ResourceType $containerResourceType `
    -ApiVersion $apiVersion -ResourceGroupName $resourceGroupName `
    -Name $containerName | Select-Object -ExpandProperty Properties

$containerProperties = @{
    "resource"=@{
        "id"=$containerGet.resource.id; 
        "partitionKey"=$containerGet.resource.partitionKey;
        "indexingPolicy"=@{"indexingMode"="none"}
    }
}

Set-AzResource -ResourceType $containerResourceType `
    -ApiVersion $apiVersion -ResourceGroupName $resourceGroupName `
    -Name $containerName -PropertyObject $containerProperties -Force 
于 2020-03-31T16:15:16.587 回答