# Tree structure and using them in cross document queries

**URL:** <https://discuss.elastic.co/t/tree-structure-and-using-them-in-cross-document-queries/119373>\
**Category:** Elasticsearch\
**Created:** [February 11, 2018, 10:22am UTC](https://discuss.elastic.co/t/tree-structure-and-using-them-in-cross-document-queries/119373 "2018-02-11T10:22:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ftaran](https://avatars.discourse-cdn.com/v4/letter/f/c77e96/32.png) [@ftaran](https://discuss.elastic.co/u/ftaran)\
**Post date:** [February 11, 2018, 10:22am UTC](https://discuss.elastic.co/t/tree-structure-and-using-them-in-cross-document-queries/119373/1 "2018-02-11T10:22:16Z")

</div>

I am trying to model cities and regions in elasticsearch, these would naturally be stored as a tree, whether they would be nested documents or parent child indexes would be dependent on how often we would have to update them.

I also would have another type of document stored, lets call this Restaurant, which would have a parentId that would reference a node in the tree.

I wanted to know if it is possible to make a single query, asking to bring back all restaurants that fall within A?

so if the trees look like this:

A\B\C  
A\D\E  
A\F\G\H

the restaurants being returned would be the ones that have parentIds of C,E,H.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 11, 2018, 10:28am UTC](https://discuss.elastic.co/t/tree-structure-and-using-them-in-cross-document-queries/119373/2 "2018-02-11T10:28:00Z")

</div>

It sounds like locations would change quite infrequently, so why not denormalize fully and store the full location information with each restaurant?

---

<div class="post-metadata">

**Author:** ![ftaran](https://avatars.discourse-cdn.com/v4/letter/f/c77e96/32.png) [@ftaran](https://discuss.elastic.co/u/ftaran)\
**Post date:** [February 11, 2018, 11:19am UTC](https://discuss.elastic.co/t/tree-structure-and-using-them-in-cross-document-queries/119373/3 "2018-02-11T11:19:04Z")

</div>

That's how we are thinking of implementing it at the moment but I would like to know about alternative approaches and whether what I have in mind is even possible.

---

<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:** [March 11, 2018, 11:19am UTC](https://discuss.elastic.co/t/tree-structure-and-using-them-in-cross-document-queries/119373/4 "2018-03-11T11:19:59Z")

</div>

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