В моем поиске у меня есть это:
body_options: { aggs: { expenditure: { terms: { field: "parent_id"},
aggs: { wbs: { terms: { field: "wbs_item_id" }, aggs: {
"committed": {
"sum": {
"field": "committed"
}
},
"invoiced_against": {
"sum": {
"field": "committed_accrued"
}
}
} } } } } }
Вот мои результаты:
"buckets" => [{
"key" => 6, "doc_count" => 3, "committed" => {
"value" => 6123.0
}, "invoiced_against" => {
"value" => 999.0
}
}, {
"key" => 7, "doc_count" => 3, "committed" => {
"value" => 0.15585599975585938e4
}, "invoiced_against" => {
"value" => 500.0
}
}, {
"key" => 4, "doc_count" => 1, "committed" => {
"value" => 0.0
}, "invoiced_against" => {
"value" => 452.0
}
}, {
"key" => 5, "doc_count" => 1, "committed" => {
"value" => 0.0
}, "invoiced_against" => {
"value" => 452.0
}
}]
Я хочу в основном добавить:
Осталось => (если зафиксировано> = invoiced_against, то зафиксировано - invoiced_against, иначе 0 end)
Таким образом, это будет выглядеть так:
"buckets" => [{
"key" => 6, "doc_count" => 3, "committed" => {
"value" => 6123.0
}, "invoiced_against" => {
"value" => 999.0
},
"remaining" => {
"value" => 5124
}
}...