How to show the aggregation result in kibana?

Hi , i have follow script do aggregation of the production year revenue. However, I dunno how can I use the visualization to present the result. Please help or point me some direction please and thanks.

POST elk_all/sales_daily
{
"code": 2,
"name": "RedTB",
"year": 2018,
"sales": 1000
}
POST elk_all/sales_daily
{
"code": 1,
"name": "BlueTB",
"year": 2018,
"sales": 1000
}
POST elk_all/sales_daily
{
"code": 2,
"name": "RedTB",
"year": 2017,
"sales": 600
}
POST elk_all/sales_daily
{
"code": 1,
"name": "BlueTB",
"year": 2017,
"sales": 920
}
POST elk_all/sales_daily
{
"code": 2,
"name": "RedTB",
"year": 2016,
"sales": 800
}
POST elk_all/sales_daily
{
"code": 1,
"name": "BlueTB",
"year": 2016,
"sales": 900
}
GET elk_all/_search
{
"size": 0,
"query": {
"bool": {
"must": {
"range": {
"year": {
"gte": "2016",
"lte": "2018"
}
}
}
}
},
"aggs": {
"group_by_code": {
"terms": {
"field": "code"
},
"aggs": {
"first_sale": {
"filter": {
"term": {
"year": "2016"
}
},
"aggs": {
"sales_value": {
"max": {
"field": "sales"
}
}
}
},
"mid_sale": {
"filter": {
"term": {
"year": "2017"
}
},
"aggs": {
"sales_value": {
"max": {
"field": "sales"
}
}
}
},
"last_sale": {
"filter": {
"term": {
"year": "2018"
}
},
"aggs": {
"sales_value": {
"max": {
"field": "sales"
}
}
}
},
"filter_positive": {
"bucket_selector": {
"buckets_path": {
"first": "first_sale>sales_value",
"mid": "mid_sale>sales_value",
"last": "last_sale>sales_value"
},
"script": "params.last > params.mid && params.mid < params.first"
}
}
}
}
}
}

For start, create a line chart with a SUM metric (anything actually if you're showing them by year), a terms aggregation on the year field or a histogram one, depending on what you want to do with it.
And if you want show them for RedTB and BlueTB separately, just click on Split Chart and then select either a terms aggregation on the name or a filter aggregation with the name as terms.

Thanks for guiding me. The line chart contains both product now. However, I try to put my aggregation script in the filter DSL it's doesn't help me to filter out the product ( code:1 ) I don't want to show in graph because code 1 is not match in my scenario. Am I missing something ?
The script work well in the dev tools ...

Can you show me a screenshot of your chart and the options that you set? It would be easier to troubleshoot that way.

Yes, here it is. Thanks..

1st jpg is the line chart output

2nd Y-Axis Metric

3rd X-Axis Metric

4th The result come from the aggregation script query I post in previous thread

Thanks in advance

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