How to display aggregations results in bar chart with vega

Currently, I want to display a barchart with y is the number Of customer value and x is the name of bucket field properties ("isActive", "isRegistered", "isBanned") as below query result:

"buckets": [
{
"key_as_string": "2018-01-01T00:00:00.000Z",
"key": 1514764800000,
"doc_count": 3900,
"isRegistered": {
"doc_count": 1000,
"NumberOfCustomer": {
"value": 1000
}
},
"isBanned": {
"doc_count": 300,
"NumberOfCustomer": {
"value": 48
}
},
"isActive": {
"doc_count": 2000,
"NumberOfCustomer": {
"value": 952
}
}
}
]

The above data is the result from below vega code:

"data": [
{
  "name": "values",
  "url": {
    "index": "cust*",
    "body": {
      "size": 0,
      "aggs": {
        "all":{
          "date_histogram": {
          "field": "timeStamp",
          "interval": "year"
          },
          "aggs": {
            "isRegistered": {
              "filter": {
                "term": {
                  "status.isRegistered": true
                }
              },
              "aggs":{
                "NumberOfCustomer": {
                  "cardinality": {  "field": "customer.customerCode.keyword"   }
                }
              }
              
            },
            "isBanned": {
              "filter": {
                "term": {
                  "status.isBanned": true
                }
              },
              "aggs":{
                "NumberOfCustomer": {
                  "cardinality": {  "field": "customer.customerCode.keyword"   }
                }
              }
              
            },
            "isActive": {
              "filter": {
                "term": {
                  "status.isActive": true
                }
              },
              "aggs":{
                "NumberOfCustomer": {
                  "cardinality": {  "field": "customer.customerCode.keyword"   }
                }
              }                  
            }
          }               
        }
      }
    }
  }
}    

]

I really don't know how to transform above data into table with 3 fields : name (isRegister, isActive, isBanned) , doc_count (3900, 300, 2000) and numberOfCustomer(1000,48,952).

Please help me, this trouble me a week and I still cannot find the solution.

Hi all,

I found the solution with the adjacency_matrix aggregations.
Here's my search code:

GET cust*/_search
{
"size": 0,
"aggs" : {
"interactions" : {
"adjacency_matrix" : {
"filters" : {
"isActive" : { "terms" : { "status.isActive": [true]} },
"isBanned" : { "terms" : { "status.isBanned" : [true] }},
"isRegistered" : { "terms" : { "status.isRegistered" : [true] }}

    }
  },
  "aggs":{
        "NumberOfCustomer": {
          "cardinality": {  "field": "customer.customerCode.keyword"   }
        }
      }
}

}
}

Thanks for viewing.

Hi Thomas,

glad to see you got it solved. I would be interested to hear why you chose to use Vega visualizations for that? This seems like a rather easy use-case that should be solvable completely via the build in chart implementations?

Cheers,
Tim

Hi Timrose,

Thanks for viewing and replying.

The reason I use vega is to:

  1. Display more information in the barchart in top & bottom of each bar
  2. Interaction when hit the the bar to navigate to another dashboard

Moreover, I really don't know how to display the nested object property name as x-scale. I'm new to kibana (just a week to get to know and work with), it would be great if you give a instructions or guideline of how to use the build in chart implementation.

Thanks,
Thomas.

Hi Thomas,

all of that are actually valid reasons. I just try to get a hold on why people start using Vega, to help us prioritize implementation of those features that are missing. So you actually would want to look in the following feature enhancements:

With having this limitations in mind your configuration for a classical bar chart that visualizes your query above, could look like that (ignore the missing charts, since I don't have data formatted that way):

Please always feel free to come back with further questions on how to create that kind of charts.

Cheers,
Tim

Thank Timrose,

It would be great if all of those feature are complete and release.

I tried this implementation before and realized that I couldn't change the filter content in the x-axis to the customized text ( x-axis show "isRegistered" instead of "status.IsRegistered:true").

Now I try with group bar chart and have some limitation, if I cannot resolve it until tomorrow i will post another topic to seek for help.

Thank you very much,
Thomas.

Actually you can change the label of every filter, by clicking on the small tag icon above the filter you are creating (beside the remove icon). That way you have the chance to specify a different label for that filter.

Cheers,
Tim

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