# Doc count with Path Hierarchy

**URL:** https://discuss.elastic.co/t/doc-count-with-path-hierarchy/247062
**Category:** Elasticsearch
**Created:** [September 1, 2020, 8:34am UTC](https://discuss.elastic.co/t/doc-count-with-path-hierarchy/247062 "2020-09-01T08:34:11Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Arun\_Kumar5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arun_kumar5/32/45221_2.png) [@Arun\_Kumar5](https://discuss.elastic.co/u/Arun_Kumar5)
#### Post date: [September 1, 2020, 8:34am UTC](https://discuss.elastic.co/t/doc-count-with-path-hierarchy/247062/1 "2020-09-01T08:34:11Z")

</div>

A index doc can belongs to multiple group (path) and i aggregated search result based on group like below:

below doc have two path as you can see in nested structure:

"NavigationCollection": [  
{  
"LangId": 1,  
"Path": "Test1\>Test2\>Test3\>Test4\>Test5"  
},

```
                    {
                        "LangId": 1,
                        "Path": "Test1>Test2>Test3>"
                    }
                ]

```

when i run aggregate query:

"aggs": {  
"NavCollection": {  
"nested": {  
"path": "NavigationCollection"  
},  
"aggs": {  
"langid": {  
"filter": {  
"term": {  
"NavigationCollection.LangId": "1"  
}  
},  
"aggs": {  
"catpath": {  
"terms": {  
"field": "NavigationCollection.Path",  
"size": 50  
}  
}  
}  
}  
}  
}

it returns data like below :  
Test1 - doc count 2  
Test2 - doc count 2  
Test3 - doc count 2  
Test4 - doc count 1  
Test5 - doc count 1

actually these all are pointing to single records. i am expecting a output like below  
Test1 - doc count 1  
Test2 - doc count 1  
Test3 - doc count 1  
Test4 - doc count 1  
Test5 - doc count 1

please help me on this.

---

<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: [September 29, 2020, 8:34am UTC](https://discuss.elastic.co/t/doc-count-with-path-hierarchy/247062/2 "2020-09-29T08:34:15Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
