Cosmos DB:范围字符串索引返回查询错误

时间:2018-01-12 11:16:40

标签: azure azure-cosmosdb

我尝试在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();

此类请求会引发错误:指定了一个无效查询,其中包含针对从索引中排除的路径的过滤器。请考虑在请求中添加允许扫描标头。

虽然几乎相同(检查相等而不是不平等)给出了正确的结果。

我是否将索引策略配置错误或者在查询时需要指定一些额外的参数?感谢

1 个答案:

答案 0 :(得分:2)

您的分区键路径也应包含在包含的路径中。它隐含地包含在过滤器中,因为您在PartitionKey = new PartitionKey("entities")中设置了它。

相关问题