I have a set of records where each record has (among other fields) a field "spam" for the amount of spam mails received and a field "total_volume" for the amount of mails, received. For each day I have several entries for different mailboxes.
So the data looks something like this:
POST _bulk
{ "index":{"_index":"test"}}
{ "spam":1, "total_volume": 2, "mailbox": "mb1", "date":"2019-01-01"}
{ "index":{"_index":"test"}}
{ "spam":1, "total_volume": 100, "mailbox": "mb2", "date":"2019-01-01"}
{ "index":{"_index":"test"}}
{ "spam":2, "total_volume": 2, "mailbox": "mb1", "date":"2019-01-02"}
{ "index":{"_index":"test"}}
{ "spam":2, "total_volume": 100, "mailbox": "mb2", "date":"2019-01-02"}
I'd like to get a visualization which would show me about 2% for 2019-01-01 and about 4% for 2019-01-02.
What I could achieve, using JSON input
{
"script": {
"lang": "painless",
"inline": "_value * 100 / doc['total_volume'].value"
}
}
was the average per day, but this results in too high values. For example on 2019-01-01 the high rate of mb1 (50%) is averaged with the 1% of mb2.
So the result is 25.5% for 2019-01-01 and 51% for 2019-01-02 instead of the required 2% and 4%.
I have no clue how I could achieve this.
Example what I used to get the results as a table: