# Script in value\_count aggregation

**URL:** <https://discuss.elastic.co/t/script-in-value-count-aggregation/19847>\
**Category:** Elasticsearch\
**Created:** [September 17, 2014, 3:07pm UTC](https://discuss.elastic.co/t/script-in-value-count-aggregation/19847 "2014-09-17T15:07:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![samchrisinger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samchrisinger/32/1278_2.png) [@samchrisinger](https://discuss.elastic.co/u/samchrisinger)\
**Post date:** [September 17, 2014, 3:07pm UTC](https://discuss.elastic.co/t/script-in-value-count-aggregation/19847/1 "2014-09-17T15:07:50Z")

</div>

I'm having an issue with an aggregate that looks like:

{  
"query": {  
"match\_all": {}  
},  
"filter": {  
"match\_all": {}  
},  
"aggs": {  
"category\_tokens": {  
"value\_count": {  
"script": "doc['title'].values.size() \> 1"  
}  
}  
}

This aggregate always returns 100,000 (the number of dummy documents), but all of my titles are 1 word long. Is it possible to use size() in this way, or am I misunderstanding the docs?

For those who like context: I'm needing to distinguish between categorical 'string' fields and text 'string fields'. Maybe there is a better way to do this? I know this is possible via a filter but I'm already needing to do aggregations and want to keep the number of requests low.

---

<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:** [July 6, 2017, 1:01am UTC](https://discuss.elastic.co/t/script-in-value-count-aggregation/19847/2 "2017-07-06T01:01:32Z")

</div>


