How to draw a pie depending on dynamic data

datasource:elasticsearch 6.5
grafana: 5.4.3

now I neeed to draw a pie which shows how many connection are there from different ip address.
since the ip address changes, and I need only top 5 or 10 on the pie, how should I do it?

I can do it in kibana, but failed in grafana, can anyone guide me ?
%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20190310154414

resolved
a data histogram needed