Hi Andrii,
Here's an example where someone else counted the number of a type of element in their data;
http://elasticsearch-users.115913.n3.nabble.com/Count-number-of-array-element-for-each-document-td4056082.html
But that example is only talking about Elasticsearch. To use a script to get the count of your "type" I think you would have to use the JSON script field in the Kibana visualizations. Click on the Advanced link at the bottom of the aggregations to see it.
Here's an example of using a JSON script in Kibana;
Your script should be simpler, like the "doc['views'].value.length"
script of the first link.
Let me know if this helps.
Regards,
Lee