# Can some help in value count aggregations

**URL:** <https://discuss.elastic.co/t/can-some-help-in-value-count-aggregations/248309>\
**Category:** Kibana\
**Created:** [September 11, 2020, 11:21am UTC](https://discuss.elastic.co/t/can-some-help-in-value-count-aggregations/248309 "2020-09-11T11:21:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjilinga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anjilinga/32/86010_2.png) [@anjilinga](https://discuss.elastic.co/u/anjilinga)\
**Post date:** [September 11, 2020, 11:21am UTC](https://discuss.elastic.co/t/can-some-help-in-value-count-aggregations/248309/1 "2020-09-11T11:21:18Z")

</div>

Hi,  
i am using value count aggragtion and with the script, pfb the script

"script": {  
"lang": "painless",  
"source": "for(int i=0; i\<1; i++){if(doc['message.code'].size() \>0 && doc['message.code'].value \>= 300){doc['message.code'].value}}"  
}  
it is showing error as invalid argument exception. if i remove the for loop it is giving result but it will not give the expected result.

can some please help on this

---

<div class="post-metadata">

**Author:** ![afharo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afharo/32/75202_2.png) [@afharo](https://discuss.elastic.co/u/afharo)\
**Post date:** [September 14, 2020, 1:27pm UTC](https://discuss.elastic.co/t/can-some-help-in-value-count-aggregations/248309/2 "2020-09-14T13:27:48Z")

</div>

Hi @anjilinga,

Can you explain what you are trying to achieve with the for loop. As far as I can see, the `i` variable from the loop is not used anywhere and that loop is only looping once through the inner code, so I would expect the same output with and without the loop.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 12, 2020, 1:27pm UTC](https://discuss.elastic.co/t/can-some-help-in-value-count-aggregations/248309/3 "2020-10-12T13:27:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
