# Find the count of nested field

**URL:** https://discuss.elastic.co/t/find-the-count-of-nested-field/39871
**Category:** Elasticsearch
**Created:** [January 22, 2016, 11:54am UTC](https://discuss.elastic.co/t/find-the-count-of-nested-field/39871 "2016-01-22T11:54:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![r.ganeshbabu](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@r.ganeshbabu](https://discuss.elastic.co/u/r.ganeshbabu)
#### Post date: [January 22, 2016, 11:54am UTC](https://discuss.elastic.co/t/find-the-count-of-nested-field/39871/1 "2016-01-22T11:54:02Z")

</div>

My document "abc" is in the below format,

{  
"name": "abc",  
"age": 25,  
"sub": [  
{  
"sub\_id": 12,  
"sub": "english",  
"mark": 89  
},  
{  
"sub\_id": 13,  
"sub": "science",  
"mark": 99  
},  
{  
"sub\_id": 14,  
"sub": "maths",  
"mark": 100  
}  
]  
}

From the above json I need to get the count of sub\_id [e.g., count(sub\_id) = 3] for a specific json document. Can anyone tell me the elastic search query to get the count. Like GET es\_stud/subject/\_search

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [January 24, 2016, 4:15am UTC](https://discuss.elastic.co/t/find-the-count-of-nested-field/39871/2 "2016-01-24T04:15:15Z")

</div>

You want to get a total of however many times a `sub_id` is mentioned in a doc?

---

<div class="post-metadata">

### Author: ![r.ganeshbabu](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@r.ganeshbabu](https://discuss.elastic.co/u/r.ganeshbabu)
#### Post date: [January 24, 2016, 10:20am UTC](https://discuss.elastic.co/t/find-the-count-of-nested-field/39871/3 "2016-01-24T10:20:54Z")

</div>

Yes @warkolm I want to get total count of **sub\_id** in a document.

---

<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 5, 2017, 11:22pm UTC](https://discuss.elastic.co/t/find-the-count-of-nested-field/39871/4 "2017-07-05T23:22:07Z")

</div>


