I'm trying to calculate the average profitmargin on the fly using histogram based on time/category/vendor etc in Kibana. The database has no calculated margins from the start (see index below).
I need to calculate the profit margin by (Netvalue - Cost)/NetValue * 100 and show the result in the the histogram.
Is it possible to make a groovy function or similar to this but using the result in a histogram?
Been trying for days to get something working but I just can't figure out which way to go or even if it's possible to do it in kibana on query level.
{
"Mycompany": {
"mappings": {
"sales": {
"properties": {
"Cost": {
"type": "double"
},
"DocumentDate": {
"format": "dateOptionalTime",
"type": "date"
},
"ItemCategory": {
"index": "not_analyzed",
"type": "string"
},
"ManufacturerName": {
"index": "not_analyzed",
"type": "string"
},
"MaterialGroup2description": {
"index": "not_analyzed",
"type": "string"
},
"MaterialGroup4description": {
"index": "not_analyzed",
"type": "string"
},
"NetPrice": {
"type": "double"
},
"NetValue": {
"type": "double"
},
"OrderQuantity": {
"type": "long"
}
}
}
}
}
}