# Question about value\_count aggregation

**URL:** <https://discuss.elastic.co/t/question-about-value-count-aggregation/19848>\
**Category:** Elasticsearch\
**Created:** [September 17, 2014, 3:41pm UTC](https://discuss.elastic.co/t/question-about-value-count-aggregation/19848 "2014-09-17T15:41:39Z")\
**Posts on this page:** 3\
**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:41pm UTC](https://discuss.elastic.co/t/question-about-value-count-aggregation/19848/1 "2014-09-17T15:41:39Z")

</div>

Hi All,

I'm having trouble with a value\_count aggregation that uses a script. For  
context I have an index of 100,000 dummy documents all with 1-word titles.

My query looks like:

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

But I get an error like: 'CompileException[[Error: No field found for  
[org.elasticsearch.index.fielddata.ScriptDocValues$Strings@1cdd34b3]'.

If it helps my mapping looks like:

"title": {  
"type": "string"  
}

What am I doing wrong here? Is it not possible to use a script like this?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8ab1b50d-ae91-4a2f-b92e-cb5ebcf9ca02%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8ab1b50d-ae91-4a2f-b92e-cb5ebcf9ca02%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [September 18, 2014, 6:07am UTC](https://discuss.elastic.co/t/question-about-value-count-aggregation/19848/2 "2014-09-18T06:07:07Z")

</div>

Hello Sam ,

The title field , i presume is a single value field which means values will  
fail.  
You need to use something like

doc['title'].value.length \> 1

Thanks  
Vineeth

On Wed, Sep 17, 2014 at 9:11 PM, Sam Chrisinger [s.chrisinger@gmail.com](mailto:s.chrisinger@gmail.com)  
wrote:

> Hi All,
> 
> I'm having trouble with a value\_count aggregation that uses a script. For  
> context I have an index of 100,000 dummy documents all with 1-word titles.
> 
> My query looks like:
> 
> {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "match\_all": {}  
> },  
> "aggs": {  
> "category\_tokens": {  
> "value\_count": {  
> "script": "doc['title'].values.size() \> 1"  
> }  
> }  
> }
> 
> But I get an error like: 'CompileException[[Error: No field found for  
> [org.elasticsearch.index.fielddata.ScriptDocValues$Strings@1cdd34b3]'.
> 
> If it helps my mapping looks like:
> 
> "title": {  
> "type": "string"  
> }
> 
> What am I doing wrong here? Is it not possible to use a script like this?
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/8ab1b50d-ae91-4a2f-b92e-cb5ebcf9ca02%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8ab1b50d-ae91-4a2f-b92e-cb5ebcf9ca02%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/8ab1b50d-ae91-4a2f-b92e-cb5ebcf9ca02%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/8ab1b50d-ae91-4a2f-b92e-cb5ebcf9ca02%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5neKgF1yEYiq2Ce6UWBv1TeptP125D\_bvi8S6FUGSPUZg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5neKgF1yEYiq2Ce6UWBv1TeptP125D_bvi8S6FUGSPUZg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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/question-about-value-count-aggregation/19848/3 "2017-07-06T01:01:26Z")

</div>


