如何在cosmos DB中进行大批量操作

How to perform large batch operation in cosmos DB

我们正在为我们的客户构建一个分析引擎。我们选择了 Cosmos DB。这样做的原因是为了存储非结构化数据。目前,对于一个客户,我们有大约 300000 条记录。

样本分析项目

{
    "adjustments": [],
    "payments": [],
    "amountReceivable": 0,
    "amountReceivablePatient": 0,
    "amountReceivableInsurance": 0,
    "id": "1_10",
    "clientID": 1,
    "chargeID": "10",
    "encounterID": "29310660",
    "patientID": "232362",
    "provider": "eeee",
    "financialClass": "kkk",
    "insurancePrimary": "jjj",
    "dateOfServiceBegin": "2019-08-19T18:30:00Z",
    "location": "test location","chargeTotal": 272,
    "chargeInsurancePrimary": 272,
    "chargePatient": 0
}

为了在仪表板中显示累积详细信息,我们创建了另一个名为摘要的集合。这将保存每月和每年的预计算数据。这是我们要用于客户端应用程序的集合。

示例摘要集合项目

{
    "id": "630b20678a4745c4881b4d5cf07bcf08",
    "clientId": 1,
    "location": "test location",
    "provider": "eee",
    "periodicity": "monthly",
    "date": "2019-10-01T00:00:00",
    "financialClass": "kkk",
    "carrier": "jjj",
    "totalChargeByDoE": 488,
    "totalChargeInsuranceByDoE": 488,
    "totalChargePatientByDoE": 0,
    "totalChargeByDoS": 488,
    "totalChargeInsuranceByDoS": 488,
    "totalChargePatientByDoS": 0,
    "totalAdjustmentByDoE": 407,
    "totalAdjustmentInsuranceByDoE": 407,
}

我们目前面临的问题是计算第一个 time.Currently 的累积记录,我们从分析收集中获取所有数据并从中填充一个列表。然后计算月度和年度明智,然后插入到摘要容器。这非常慢并且消耗更多的 RU。此问题仅针对现有数据。我们已经实施了更改提要处理器来处理实时数据。有什么方法可以减少这个过程时间和 RU?提前致谢。

根据你的描述,你想计算历史数据以实现 Group By 月或年功能和 upsert 汇总收集,如果我没有误解的话。

你可以使用 sql 中 .net sdk and js sdk and Aggregate feature like SUM 支持的分组依据 query.No 需要加载所有数据并按 yourself.However 计算,如果你的计算逻辑很复杂, 看来你避无可避了

另外,当您准备汇总汇总添加数据时,可以考虑使用bulk executor which is more efficient. Or you could save the data and generate json file so that you could import data with migration tool