【发布时间】:2018-01-12 11:16:40
【问题描述】:
我正在尝试为 CosmosDB 文档集合创建自定义索引策略,以便在索引中仅包含 1 个字段。
索引策略如下:
new IndexingPolicy
{
Automatic = true,
IndexingMode = IndexingMode.Consistent,
ExcludedPaths = new Collection<ExcludedPath>(new[]
{
new ExcludedPath { Path = "/*" }
}),
IncludedPaths = new Collection<IncludedPath>(new[]
{
new IncludedPath
{
Path = "/Id/?",
Indexes = new Collection<Index>(new Index[] { new RangeIndex(DataType.String) {Precision = -1 } })
}
})
};
然后我对文档集合进行查询:
CosmosClient.CreateDocumentQuery<Entity>(
CollectionUri(docCollection),
"SELECT x from x where x.Id != \"\" ",
new FeedOptions
{
MaxItemCount = 100,
RequestContinuation = null,
EnableCrossPartitionQuery = false,
PartitionKey = new PartitionKey("entities"),
}).AsDocumentQuery();
此类请求会引发错误:指定了无效查询,过滤器针对从索引中排除的路径。考虑在请求中添加允许扫描标头。
虽然几乎相同(检查相等而不是不相等)给出了正确的结果。
是我配置索引策略错误还是在查询时需要指定一些额外的参数?谢谢
【问题讨论】:
标签: azure azure-cosmosdb