# Path\_hierarchy aggregation for specific depth

**URL:** <https://discuss.elastic.co/t/path-hierarchy-aggregation-for-specific-depth/115151>\
**Category:** Elasticsearch\
**Created:** [January 11, 2018, 5:46pm UTC](https://discuss.elastic.co/t/path-hierarchy-aggregation-for-specific-depth/115151 "2018-01-11T17:46:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![apa512](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apa512/32/26483_2.png) [@apa512](https://discuss.elastic.co/u/apa512)\
**Post date:** [January 11, 2018, 5:46pm UTC](https://discuss.elastic.co/t/path-hierarchy-aggregation-for-specific-depth/115151/1 "2018-01-11T17:46:18Z")

</div>

I'm using the path\_hierarchy tokenizer to index file system paths and it works perfectly for querying. However, I'm also interested in finding all possible paths for a certain depth.

My approach so far has been to use an aggregation with a filter:

```
{"terms": {"field": "path",
                  "include" "/[^/]+"}}

```

This would give me everything directly under / but using a regex is too slow with the index I'm using. Is there a way to solve this with the path\_hierarchy tokenizer that I'm missing, or can someone point me in another direction?

---

<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:** [February 8, 2018, 5:46pm UTC](https://discuss.elastic.co/t/path-hierarchy-aggregation-for-specific-depth/115151/2 "2018-02-08T17:46:32Z")

</div>

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