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 ?

a data histogram needed