# ElasticSearch: Query to get count of objects in a nested field

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-to-get-count-of-objects-in-a-nested-field/13172>\
**Category:** Elasticsearch\
**Created:** [August 12, 2013, 9:41am UTC](https://discuss.elastic.co/t/elasticsearch-query-to-get-count-of-objects-in-a-nested-field/13172 "2013-08-12T09:41:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![karan](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@karan](https://discuss.elastic.co/u/karan)\
**Post date:** [August 12, 2013, 9:41am UTC](https://discuss.elastic.co/t/elasticsearch-query-to-get-count-of-objects-in-a-nested-field/13172/1 "2013-08-12T09:41:55Z")

</div>

Hello Everyone,

I needed some help please.  
I needed to create a count query on nested objects in a field, across all  
documents. Each document json has a many fields. One particular field  
called "hotlinks" comprises of many internal dynamic object fields.

Doc1:  
{  
hotlinks : { 112222:{....} , 333333: {.....} , 545555: {.....} }  
}

Doc2:  
{  
hotlinks : { 67756:{....} , 756767: {.....} , 1111111: {.....} }  
}

Each document has a hotlinks fields. The hotlinks field comprises of varied  
inner hotlink objects. Each key is a java unique id and has objects that  
contain data (inner fields)  
I needed a way to get the count of all the inner nested objects of the  
field – ‘hotlinks’. For example the summation of inner objects of hotlinks  
in doc1 and doc2 would be 6. Is there any way to do this in ES via a single  
query to get the count across all documents.

Thanks a lot,  
Karan

--  
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).  
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, 2:21am UTC](https://discuss.elastic.co/t/elasticsearch-query-to-get-count-of-objects-in-a-nested-field/13172/2 "2017-07-06T02:21:37Z")

</div>


