Cosmos DB通过Azure RM设置索引策略

时间:2020-03-31 11:19:58

标签: powershell azure-cosmosdb azure-rm

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

select
    to_char(date('0001-01-01') + year(current date) years - 1 year, 'yyyymmdd') first_day_of_the_year,
    to_char(date('0001-01-01') + year(current date) years - 1 day, 'yyyymmdd')  last_day_of_the_year
from sysibm. sysdummy1

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 

}

更新: 尝试过:

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

没有运气

1 个答案:

答案 0 :(得分:1)

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

更新:由于不建议使用AzureRM,因此此示例使用AzResource。

$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