首页 > 解决方案 > 从 CosmosDB 获取最大数量的有效方法

问题描述

我有大量文件(约 200 万份)。我必须查询num给定字典键的最高值。

以下两个文档的预期输出将是'3'给定的 key '85642768'

文件1:

{
    "id": "fb41ecd9-2761-41f4-87ca-aa4bf59f9d83",
    "Key": "Key123",
    "Dict": {
        "85642766": {
            "num": 1,
            "str": "str1"
        },
        "85642767": {
            "num": 1,
            "str": "str2"
        },
        "85642768": {
            "num": 2,
            "str": "str3"
        }
    }
}

文件2:

{
    "id": "821cf017-421a-422a-b082-45e77228dca3",
    "Key": "Key456",
    "Dict": {
        "85642766": {
            "num": 1,
            "str": "str1"
        },
        "85642767": {
            "num": 2,
            "str": "str2"
        },
        "85642768": {
            "num": 3,
            "str": "str3"
        }
    }
}

目前我有 250K 的唯一文档。我正在根据Key8000 个批次的列表下载文档列表。在同一位置需要 14 分钟,10000 个 RU。

我也有一个基于的索引Key。有没有更好的方法来减少搜索时间?

标签: c#azure-cosmosdb

解决方案


正如上面的评论所说,你可以使用 sql 来做这件事。

请尝试类似这样的 sql:

SELECT value max(c.Dict["85642768"].num) from c

希望这可以帮到你。


推荐阅读