Azure cosmosdb Azure Cosmos DB中的排除路径
什么是正确的JSON,可以从Azure CosmosDB未索引的输入JSON中排除某些键。我们正在mongodb模式下使用CosmosDB。计划在创建集合后更改Azure门户上的索引配置 正在使用的示例输入JsonAzure cosmosdb Azure Cosmos DB中的排除路径,azure-cosmosdb,Azure Cosmosdb,什么是正确的JSON,可以从Azure CosmosDB未索引的输入JSON中排除某些键。我们正在mongodb模式下使用CosmosDB。计划在创建集合后更改Azure门户上的索引配置 正在使用的示例输入Json { "name": "test", "age": 1, "location": "l1", "height":5.7 } 如果我要在索引中包括姓名和年龄,并从索引中删除位置和高度,IncludedPath和ExcludedPath是什么样子的 最终使
{
"name": "test",
"age": 1,
"location": "l1",
"height":5.7
}
如果我要在索引中包括姓名和年龄,并从索引中删除位置和高度,IncludedPath和ExcludedPath是什么样子的 最终使其与以下规范配合使用:-
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [{
"path": "/*",
"indexes": [{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}],
"excludedPaths": [{
"path": "/\"location\"/?"
},
{
"path": "/\"height\"/?"
}
]
}
看起来底层实现已经发生了变化,在编写文档时,还没有涵盖MongoDB风格的CosmosBD中的索引策略的变化。因为文档实际上是以有线方式存储的,其中所有键都从根$v开始,所有标量字段都存储为文档,包含值和类型信息。因此,您的文档将存储如下内容:
{
'_etag': '"2f00T0da-0000-0d00-0000-4cd987940000"',
'id': 'SDSDFASDFASFAFASDFASDF',
'_self': 'dbs/sMsxAA==/colls/dVsxAI8MBXI=/docs/sMsxAI8MBXIKAAAAAAAAAA==/',
'_rid': 'sMsxAI8MBXIKAAAAAAAAAA==',
'$t': 3,
'_attachments': 'attachments/',
'$v': {
'_id': {
'$t': 7,
'$v': "\\Ù\x87\x14\x01\x15['\x18m\x01ú"
},
'name': {
'$t': 2,
'$v': 'test'
},
'age': {
'$t': 1,
'$v': 1
},
...
},
'_ts': 1557759892
}
因此,索引策略路径需要包括根$v,并使用/*(对象)而不是/?(标量)
附言:
此外,MongoAPI还可用于删除所有默认索引,并根据需要创建特定索引
你看过Azure门户网站上关于定制索引策略的文档了吗?@DavidMakogon:看过,但不太清楚。在mongoDB模式下,API添加了一些额外的键,这些键需要在索引规范之下。其中一些是_ts、_附件等。只是在include规范中用*覆盖了它们,并在exclude规范中声明了我不需要的。在撰写本文时,Azure门户针对无效路径给出了以下错误消息:无法接受索引路径“…”,在位置“0”附近失败。请确保路径是有效的路径。常见错误包括无效字符或标签周围缺少引号。为了更好的可读性,单引号也同样适用:“路径”:“高度/?”
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number"
},
{
"kind": "Hash",
"dataType": "String"
}
]
}
],
"excludedPaths": [
{"path": "/\"$v\"/\"location\"/*"},
{"path": "/\"$v\"/\"height\"/*"}
]
}