Azure CosmosDb: Order-by item requires a range index

poo*_*kie 0 azure azure-cosmosdb

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

Here is my query:

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
Run Code Online (Sandbox Code Playgroud)

However, I get the exception:

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

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

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

PS_ts属性对我不利,因为我不想在插入记录时进行订购。

Sam*_*hra 6

ORDER BY直接从索引提供服务,因此它要求按物料对订单进行范围索引(与哈希索引相反)。

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

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

    {
        "automatic": true,
        "indexingMode": "consistent",
        "includedPaths": [
            {
                "path": "/", 
                "indexes": [ 
                    { "kind": "Range", "dataType": "Number", "precision": -1 }, 
                    { "kind": "Range", "dataType": "String", "precision": -1 }
                ]
            }
        ]
    }
Run Code Online (Sandbox Code Playgroud)