How can i Disply the result of division between two field?


(Ningchuan Mao) #1

Hi Guys, currently, i have a requirement about kibana visualize tab, i want to display the division result of two sum(field). how can i display that result.

my script is
{
"query": {
"bool": {
"must": [
{
"query_string": {
"analyze_wildcard": true,
"query": "站点"
}
},
{
"match_phrase": {
"tradeType": {
"query": "Recharge"
}
}
},
{
"range": {
"dbTime": {
"gte": 1503803048541,
"lte": 1503889448541,
"format": "epoch_millis"
}
}
}
],
"must_not": []
}
},
"size": 0,
"_source": {
"excludes": []
},
"aggs": {
"5": {
"date_range": {
"field": "dbTime",
"ranges": [
{
"from": "now-1d/d+2h",
"to": "now/d+2h"
}
]
},
"aggs": {
"4": {
"terms": {
"field": "stationCode.keyword",
"size": 100,
"order": {
"1": "desc"
}
},
"aggs": {
"1": {
"sum": {
"field": "payAmount"
}
},
"3": {
"sum": {
"field": "tradeAmount"
}
},
"division" : {
"bucket_script": {
"buckets_path": {
"my_var1": "1",
"my_var2": "3"
},
"script": "params.my_var1 / params.my_var2"
}
}
}
}
}
}
}
}

i want to display the division in the table.


(kulkarni) #2

Hi

Possibly this can be achieved by Pipeline aggregations in ES. . These are aggregations that work on the result of other aggregations. In your example, you could use a bucket_script pipeline aggregation. For ex: I just considered sum_1 and sum_2

"aggs": {
  "sum_1": {
    "sum": {
      "field": "abc"
    }
  },
  "sum_2": {
    "sum": {
      "field": "def"
    }
  },
  "division": {
    "bucket_script": {
      "buckets_path": {
        "my_var1": "sum_1",
        "my_var2": "sum_2"
      },
      "script": "params.my_var1 / params.my_var2"
    }
  }
}

Also follow along the math count detailed post in kibana discuss :Doing Math over count of events . This might help as well.

thanks
Rashmi


(Ningchuan Mao) #3

@rashmi, thanks for your answer, yeah, you are right, i just don'w know how to display the result of division in kibana visualize data table, do you know how to let the result display in the data table?thanks


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.