elasticsearch - 如何在 ES 存储桶中填充缺失的数据以与之前的聚合?
问题描述
我试图弄清楚如何在 ES 中进行这种聚合,我需要将丢失的数据填充到存储桶中。
假设我的文档看起来像这样(非常简化):
Score {
orgId: Long
date: Date
score: Float
status: ("draft" | "complete")
}
我想要的是组织的最后得分状态为“完成”的组织每天的平均得分......可能不是每天都有得分,但我想包括所有后续日子的最后得分,如果它在“完成”状态。如果我们稍后获得“草稿”状态分数,我不想将该组织包括在该日期和后续日期的平均值中,直到有另一个状态为“已完成”的分数。
所以这里有一个例子:
{orgId: 1, date: '5/19/2021', score: 0.1, status: 'complete'}
{orgId: 2, date: '5/19/2021', score: 0.2, status: 'complete'}
{orgId: 3, date: '5/19/2021', score: 0.5, status: 'complete'}
{orgId: 1, date: '5/21/2021', score: 0.1, status: 'draft'}
{orgId: 1, date: '5/23/2021', score: 0.5, status: 'complete'}
{orgId: 1, date: '5/25/2021', score: 0.5, status: 'draft'}
所以为此我想回来:
{date: '5/19/2021', avg: 0.266667}
{date: '5/20/2021', avg: 0.266667}
{date: '5/21/2021', avg: 0.35}
{date: '5/22/2021', avg: 0.35}
{date: '5/23/2021', avg: 0.4}
{date: '5/24/2021', avg: 0.4}
{date: '5/25/2021', avg: 0.35}
我对 ES 很陌生,所以我对如何实现这一点有点迷茫。任何帮助表示赞赏。
解决方案
推荐阅读
- python-3.x - 如何在第一次出现字符串后插入 string1,在第二次出现字符串后插入 string2,依此类推?
- javascript - 将选中的 Li 移动到 UL 的底部
- html - CSS Flexbox:将两个项目保留在同一列中
- java - java中的模运算符
- sapui5 - UI5:隐藏 UploadSet 的“未找到文件”图标
- asp.net-core - 在 v8.0 中将多个源自动映射到单个目标
- dafny - 涉及数组的验证
- python - TypeError:一元的错误操作数类型〜:'bytes':一串字节的补码
- c# - 发布无法加载文件或程序集 CefSharp.Core.dll
- python - Python 泛型类型包装器