# Aggregation module - value\_count clarification/problem

**URL:** <https://discuss.elastic.co/t/aggregation-module-value-count-clarification-problem/15412>\
**Category:** Elasticsearch\
**Created:** [January 25, 2014, 4:56am UTC](https://discuss.elastic.co/t/aggregation-module-value-count-clarification-problem/15412 "2014-01-25T04:56:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![watsindename](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/watsindename/32/1846_2.png) [@watsindename](https://discuss.elastic.co/u/watsindename)\
**Post date:** [January 25, 2014, 4:56am UTC](https://discuss.elastic.co/t/aggregation-module-value-count-clarification-problem/15412/1 "2014-01-25T04:56:43Z")

</div>

Hi,

I am trying to get the unique number of values for a given field. From my  
understanding of "value\_count[http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-metrics-valuecount-aggregation.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-metrics-valuecount-aggregation.html)"  
it counts the number of values that are extracted from the aggregated  
documents. After the steps in es-agg-test-1.sh, and on querying for unique  
values of field "k" the response that I get is

{  
"took": 16,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 20,  
"max\_score": 1,  
"hits": [] //deleted content of "hits" to shorten the paste  
},  
"aggregations": {  
"k\_count": {  
"value": 22  
}  
}  
}

How can I be getting "value" 22, shouldn't it be 20 as thats the number of  
unique "k" values in documents.

Another example, on querying for unique values of field "t" I get the  
following response

{  
"took": 7,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 20,  
"max\_score": 1,  
"hits": [] //deleted content of "hits" to shorten the paste  
},  
"aggregations": {  
"k\_count": {  
"value": 20  
}  
}  
}

Again, shouldn't the "value" be 1, as the only value of "t" is 23 in all  
documents.

--  
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/23a23530-a690-4c93-b67e-6e6fe44c6ee1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/23a23530-a690-4c93-b67e-6e6fe44c6ee1%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![watsindename](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/watsindename/32/1846_2.png) [@watsindename](https://discuss.elastic.co/u/watsindename)\
**Post date:** [January 25, 2014, 4:59am UTC](https://discuss.elastic.co/t/aggregation-module-value-count-clarification-problem/15412/2 "2014-01-25T04:59:11Z")

</div>

The link to gist is  
[https://gist.github.com/shivprak/8611922#file-es-agg-test-1-sh](https://gist.github.com/shivprak/8611922#file-es-agg-test-1-sh)

On Friday, January 24, 2014 8:56:43 PM UTC-8, [watsin...@gmail.com](mailto:watsin...@gmail.com) wrote:

> Hi,
> 
> I am trying to get the unique number of values for a given field. From my  
> understanding of "value\_count[http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-metrics-valuecount-aggregation.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-metrics-valuecount-aggregation.html)"  
> it counts the number of values that are extracted from the aggregated  
> documents. After the steps in es-agg-test-1.sh, and on querying for  
> unique values of field "k" the response that I get is
> 
> {  
> "took": 16,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 20,  
> "max\_score": 1,  
> "hits": //deleted content of "hits" to shorten the paste  
> },  
> "aggregations": {  
> "k\_count": {  
> "value": 22  
> }  
> }  
> }
> 
> How can I be getting "value" 22, shouldn't it be 20 as thats the number of  
> unique "k" values in documents.
> 
> Another example, on querying for unique values of field "t" I get the  
> following response
> 
> {  
> "took": 7,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 20,  
> "max\_score": 1,  
> "hits": //deleted content of "hits" to shorten the paste  
> },  
> "aggregations": {  
> "k\_count": {  
> "value": 20  
> }  
> }  
> }
> 
> Again, shouldn't the "value" be 1, as the only value of "t" is 23 in all  
> documents.

--  
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/3f822944-898b-444a-b748-6be2f72809b6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3f822944-898b-444a-b748-6be2f72809b6%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:54am UTC](https://discuss.elastic.co/t/aggregation-module-value-count-clarification-problem/15412/3 "2017-07-06T01:54:50Z")

</div>


