# Get the counts at each levels in a tree like document structure

**URL:** <https://discuss.elastic.co/t/get-the-counts-at-each-levels-in-a-tree-like-document-structure/139533>\
**Category:** Elasticsearch\
**Created:** [July 11, 2018, 10:11am UTC](https://discuss.elastic.co/t/get-the-counts-at-each-levels-in-a-tree-like-document-structure/139533 "2018-07-11T10:11:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikhilkvn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikhilkvn/32/85872_2.png) [@nikhilkvn](https://discuss.elastic.co/u/nikhilkvn)\
**Post date:** [July 11, 2018, 10:11am UTC](https://discuss.elastic.co/t/get-the-counts-at-each-levels-in-a-tree-like-document-structure/139533/1 "2018-07-11T10:11:14Z")

</div>

Example data  
{  
"userName": "spyderman",  
"phoneNumber": "123ertre67890",  
"devicegroup": "Globe/India/Delhi/Parkstreet/building0/401B",  
"address": "#complete address with postal codes",  
},  
{  
"userName": "batman",  
"phoneNumber": "12345fas890",  
"devicegroup": "Globe/India/delhi/Parkstreet/building0/402B",  
"address": "#complete address with postal codes",  
},  
{  
"userName": "superman",  
"phoneNumber": "123456asf0",  
"devicegroup": "Globe/India/delhi/gandhistreet/building0/401A",  
"address": "#complete address with postal codes",  
},

I wish to get the counts at each level:  
The documents will not be duplicated (generates one per user registration into the system)  
output desired:

# countries @global level

# cities @ country level

# buildings @ street level

# users @ street level and # users @ building level

I was thinking to use path tokenizers but then not sure how i can get the counts in the way i desire. can someone guide in this regard.

---

<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:** [July 11, 2018, 10:12am UTC](https://discuss.elastic.co/t/get-the-counts-at-each-levels-in-a-tree-like-document-structure/139533/2 "2018-07-11T10:12:10Z")

</div>

Please don't post the same question more than once, it makes it harder for people to help.

Let's continue the discussion in [Get the count in a tree like structure of items](https://discuss.elastic.co/t/get-the-count-in-a-tree-like-structure-of-items/139532)

---

<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:** [July 11, 2018, 10:12am UTC](https://discuss.elastic.co/t/get-the-counts-at-each-levels-in-a-tree-like-document-structure/139533/3 "2018-07-11T10:12:13Z")

</div>


