Azure CosmosDb:按项目排序需要范围索引
我正在通过Azure门户“查询资源管理器”执行一个简单的查询 我的问题是:Azure CosmosDb:按项目排序需要范围索引,azure,azure-cosmosdb,Azure,Azure Cosmosdb,我正在通过Azure门户“查询资源管理器”执行一个简单的查询 我的问题是: 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要求在相应的索引
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要求在相应的索引路径上定义范围索引
没有关于错误的帮助链接,我无法从错误消息中得出结论
这意味着什么,为什么我的查询失败了,我如何修复它
p.S.由于我不想在插入记录时订购,
\u ts
属性对我没有好处 ORDER BY直接从索引中提供,因此需要对ORDER BY项进行范围索引(与哈希索引相反)
虽然只能将order by item索引为range(对于数字和字符串),但我的建议是将所有路径索引为range,精度为-1
基本上,您需要将集合的索引策略更新为以下内容:
{
"automatic": true,
"indexingMode": "consistent",
"includedPaths": [
{
"path": "/",
"indexes": [
{ "kind": "Range", "dataType": "Number", "precision": -1 },
{ "kind": "Range", "dataType": "String", "precision": -1 }
]
}
]
}
ORDER BY直接从索引中提供,因此它需要对ORDER BY项进行范围索引(与哈希索引相反) 虽然只能将order by item索引为range(对于数字和字符串),但我的建议是将所有路径索引为range,精度为-1 基本上,您需要将集合的索引策略更新为以下内容:
{
"automatic": true,
"indexingMode": "consistent",
"includedPaths": [
{
"path": "/",
"indexes": [
{ "kind": "Range", "dataType": "Number", "precision": -1 },
{ "kind": "Range", "dataType": "String", "precision": -1 }
]
}
]
}