# How do I index hierarchical data?

**URL:** <https://discuss.elastic.co/t/how-do-i-index-hierarchical-data/55643>\
**Category:** Elasticsearch\
**Created:** [July 15, 2016, 5:16pm UTC](https://discuss.elastic.co/t/how-do-i-index-hierarchical-data/55643 "2016-07-15T17:16:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![caddala](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@caddala](https://discuss.elastic.co/u/caddala)\
**Post date:** [July 15, 2016, 5:16pm UTC](https://discuss.elastic.co/t/how-do-i-index-hierarchical-data/55643/1 "2016-07-15T17:16:09Z")

</div>

I have data similar to file paths that I would like to index. (basically list of tokens separated by delimiter)

```
> Ex data:
> a/b/c/d/e
> a/b/c/
> a/m/n
> x/y/z

```

Once I index, I should be able to query to get the immediate children for a given token as shown below.

```
> For prefix of a, immediate children are [b, m]
> for prefix of x, immediate children are [y]
> Also tokens at root would be [a,x]
```

---

<div class="post-metadata">

**Author:** ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)\
**Post date:** [July 17, 2016, 12:00am UTC](https://discuss.elastic.co/t/how-do-i-index-hierarchical-data/55643/2 "2016-07-17T00:00:10Z")

</div>

Have a look at the [Path Hierarchy Tokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-pathhierarchy-tokenizer.html).

---

<div class="post-metadata">

**Author:** ![caddala](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@caddala](https://discuss.elastic.co/u/caddala)\
**Post date:** [July 17, 2016, 1:56am UTC](https://discuss.elastic.co/t/how-do-i-index-hierarchical-data/55643/3 "2016-07-17T01:56:23Z")

</div>

I actually looked into it. I was able to use the path tokenizer so that a string such a a.b.c would create [a,a.b, a.b.c] terms. But I am not sure if that would be able to address the kind of search query I was looking for.

I looked at terms aggregation which could help with this kinda data but with lots of data, terms aggregation is not able to support this kind of real time query. For example just to find out the root token, it has to do an aggregation at that level. Imagine having a millions of documents and doing aggregation at that level.

---

<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, 10:35pm UTC](https://discuss.elastic.co/t/how-do-i-index-hierarchical-data/55643/4 "2017-07-05T22:35:01Z")

</div>


