Azure CosmosDb:订单项需要一个范围索引 [英] Azure CosmosDb: Order-by item requires a range index

查看:52
本文介绍了Azure CosmosDb:订单项需要一个范围索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Azure门户查询资源管理器"执行简单的查询.

I'm performing a simple query via the Azure Portal "Query Explorer".

这是我的查询:

SELECT * FROM c
WHERE c.DataType = 'Fruit' 
AND c.ExperimentIdentifier = 'prod' 
AND c.Param = 'banana' 
AND Contains(c.SampleDateTime, '20171029')
ORDER BY c.SampleDateTime DESC

但是,我得到了例外:

按订单商品需要在相应的索引路径上定义范围索引.

Order-by item requires a range index to be defined on the corresponding index path.

没有链接可以帮助您解决该错误,并且从该错误消息中我也无法幸免.

There is no link to help regarding the error and I cannot make heads from tails, from that error message.

这是什么意思,为什么我的查询失败,该如何解决?

What does it mean, why is my query failing and how can I fix it?

PS ._ts属性对我来说不好,因为我不想在插入记录时订购.

P.S. the _ts property is no good to me as I do not want to order by the time the records were inserted.

推荐答案

ORDER BY是直接从索引提供的,因此它要求按物料对订单进行范围索引(而不是哈希索引).

ORDER BY is served directly from the index and thus it requires the order by item to be Range indexed (as opposed to Hash indexed).

虽然您只能将order-by项索引为范围(对于数字和字符串),但我的建议是将所有路径索引为范围为-1的精度.

While you could only index the order-by item as range (for both numbers and string), my advice is to index all paths as range with precision of -1.

基本上,您需要将集合的索引编制策略更新为以下形式:

Basically, you'd need to update the indexing policy of your collection to be something like this:

    {
        "automatic": true,
        "indexingMode": "consistent",
        "includedPaths": [
            {
                "path": "/", 
                "indexes": [ 
                    { "kind": "Range", "dataType": "Number", "precision": -1 }, 
                    { "kind": "Range", "dataType": "String", "precision": -1 }
                ]
            }
        ]
    }

这篇关于Azure CosmosDb:订单项需要一个范围索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆