Azure DocumentDb:不带索引的查询
当从索引中排除所有路径时,为什么我仍然能够对ID以外的字段执行成功的查询 排除所有路径:Azure DocumentDb:不带索引的查询,azure,azure-cosmosdb,Azure,Azure Cosmosdb,当从索引中排除所有路径时,为什么我仍然能够对ID以外的字段执行成功的查询 排除所有路径: collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath() { Path = "/*" }); 查询: SELECT * FROM c where c.Key = "117dfd49-a71d-413b-a9b1-841e88db06e8" 因此: 关闭索引后,只能通过文档的自链接或使用ID的查询来访问文档
collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath()
{
Path = "/*"
});
查询:
SELECT * FROM c where c.Key = "117dfd49-a71d-413b-a9b1-841e88db06e8"
因此:
关闭索引后,只能通过文档的自链接或使用ID的查询来访问文档
编辑:
查看索引策略时,我看到哪些路径未被排除:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
},
{
"path": "/\"_ts\"/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": []
}
我做错了什么?
我使用的是一致性索引,所以如果我理解正确,这肯定不是索引传播的最终一致性问题
以下是所有代码:
var collectionSpec = new DocumentCollection { Id = collectionId };
var requestOptions = new RequestOptions { OfferType = "S1" };
collection = Client.CreateDocumentCollectionAsync(databaseLink, collectionSpec, requestOptions).Result;
collection.IndexingPolicy.IndexingMode = IndexingMode.Consistent;
collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath()
{
Path = "/*"
});
在设置新的索引策略后,我没有看到任何替换文档集合的调用 您需要调用
Client.ReplaceDocumentCollectionAsync()
,使您的索引策略更改生效
方法文档是
这里是DocumentDB团队关于在线更新索引策略的文章(这是指需要调用
ReplaceDocumentCollectionAsync()
)。您需要在client.CreateDocumentCollectionAsync()之前更改代码片段以定义集合规范上的索引策略
-以便将其包含在创建DocumentDB集合的网络请求中
在创建集合时设置自定义索引策略
var collection=newdocumentcollection{Id=“myCollection”};
collection.IndexingPolicy.IndexingMode=IndexingMode.Consistent;
collection.IndexingPolicy.IncludedPath.Add(
新IncludedPath{
Path=“/*”,
索引=新集合{
新的RangeIndex(DataType.String){Precision=-1},
新的RangeIndex(DataType.Number){Precision=-1}
}
});
等待client.CreateDocumentCollectionAsync(database.SelfLink,collection);
更新现有集合上的索引策略
As-您还可以使用Client.ReplaceDocumentCollectionAsync()
更新现有集合上的索引策略