【问题标题】:Cosmos DB: range string index return query errorCosmos DB:范围字符串索引返回查询错误
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 非常感谢!这有帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-25
    • 2015-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多