# Search based on variables' count

**URL:** <https://discuss.elastic.co/t/search-based-on-variables-count/47004>\
**Category:** Kibana\
**Created:** [April 11, 2016, 3:20pm UTC](https://discuss.elastic.co/t/search-based-on-variables-count/47004 "2016-04-11T15:20:07Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)\
**Post date:** [April 12, 2016, 3:45pm UTC](https://discuss.elastic.co/t/search-based-on-variables-count/47004/4 "2016-04-12T15:45:09Z")

</div>

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](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;

> [@Display concurrency in data on Kibana](https://discuss.elastic.co/t/display-concurrency-in-data-on-kibana/26006/12):
>
> I also tried this but it doesn't remove the field parameter as promised. With the following json input: { "interval":"minute", "script": "start = doc['recordStart'].value; duration = doc['recordDuration'].value; l = []; for (long i = 0; i \< duration; i += 60000) { l.add(start + i); }; return l;", "field":null, "lang": "groovy" } I get the following request "aggs": { "2": { "date\_histogram": { "field": null, "interval": "minute", "pre\_zone": "+02:00", "pre\_zone\_adjust\_large…

Your script should be simpler, like the `"doc['views'].value.length" ` script of the first link.

Let me know if this helps.

Regards,  
Lee

---

_[View the full topic](https://discuss.elastic.co/t/search-based-on-variables-count/47004)._
