How does Kibana get available fields stats?

Thanks @weltenwort. But I am more interested in how many different values and its distribution we have for certain attributes (i.e: country) rather than that kind stats. Maybe my question wasn't clear.