错误:order by 查询没有可以从中提供服务的相应复合索引

rbo*_*hac 1 azure azure-cosmosdb azure-cosmosdb-sqlapi

执行以下查询时,我收到一个错误

select * from c order by c.Agent.LastStateChangeUnixTime desc,c.Priority asc

order by 查询没有相应的复合索引可以从中提供服务

我在此处此处的文档中添加了复合索引

我的综合指数错了吗?还是我错过了其他东西?

我的索引设置是:

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/*"
        }
    ],
    "excludedPaths": [
        {
            "path": "/\"_etag\"/?"
        }
    ],
    "compositeIndexes": [
        [
            {
                "path": "/Priority",
                "order": "descending"
            },
            {
                "path": "/Agent/LastStateChangeUnixTime",
                "order": "ascending"
            }
        ]
    ]
}
Run Code Online (Sandbox Code Playgroud)

示例对象:

{
    "Agent": {
        "TenantId": 999999,
        "PrimaryState": "Null",
        "PendingState": "Null",
        "LastStateChange": "2020-01-18T05:48:11.5397269+00:00",
        "LastStateChangeUnixTime": 1579326491,
        "Notes": null,
        "AgentId": 123,
        "id": "agent-123"
    },
    "AgentId": 123,
    "SkillName": "English",
    "id": "SkillName123",
    "Priority": 10,
    "_rid": "SVIMANKqJboCAAAAAAAAAA==",
    "_self": "dbs/SVIMAA==/colls/SVIMANKqJbo=/docs/SVIMANKqJboCAAAAAAAAAA==/",
    "_etag": "\"2200819a-0000-0700-0000-5e229c1d0000\"",
    "_attachments": "attachments/",
    "_ts": 1579326493
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*own 5

是的,您的复合索引对于此查询不正确。它们出现的顺序很重要,因此 WHERE 子句需要匹配顺序。

将以下内容更改或添加到您的复合索引中。

"compositeIndexes": [
    [
        {
            "path": "/Agent/LastStateChangeUnixTime",
            "order": "descending"
        },
        {
            "path": "/Priority",
            "order": "ascending"
        }
    ]
]
Run Code Online (Sandbox Code Playgroud)

  • 大家好,我来自 CosmosDB 工程团队。在复合索引完全构建之前,我们不会使用它,因此即使创建了匹配的复合索引,错误也可能会持续一段时间。如果您可以监控集合的重新索引器进度并在进度达到 100% 后重试,那么您不应遇到此错误。我们正在努力改进错误消息以指示这种特殊情况,指示在构建复合索引时不能使用复合索引,而不是错误地指示不存在复合索引。 (2认同)