为什么 CosmosDB 在通过 ARM 模板创建文档集合时会忽略索引?
Why does CosmosDB ignore indexes when creating document collection via ARM template?
给定 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',但它会忽略 'indexes'。我是做错了什么还是在预料之中?
最近对 Cosmos DB 索引引擎进行了更改,默认为字符串和数字的范围索引,精度为 -1。
ARM 模板和文档尚未更新以将其反映为默认值。
如果 non-default 对索引策略进行了更改,例如添加空间索引,它们将包含在已部署的容器中。
给定 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',但它会忽略 'indexes'。我是做错了什么还是在预料之中?
最近对 Cosmos DB 索引引擎进行了更改,默认为字符串和数字的范围索引,精度为 -1。
ARM 模板和文档尚未更新以将其反映为默认值。
如果 non-default 对索引策略进行了更改,例如添加空间索引,它们将包含在已部署的容器中。