Parent child deep level hierarchy

Although using deep parent-child relationships at first may seem like a natural fit to this problem, it may not be the best way to model it in Elasticsearch, especially if the depth of the hierarchies can vary. Flattening data, at least to some extent, is often a better approach as it can scale and perform better as all data does not need to reside in the same shard. The drawback is naturally that more entities in the hierarchy need to be updated when privileges change. Your access patterns, rate of change and hierarchy may affect the level of flattening that is appropriate.

One way of modelling this could e.g. be to store all folders in the hierarchy as individual parent level documents and all resources as child documents linked to a parent. Each folder could hold the full path, possibly analyzed using the path hierarchy tokenizer.

The tokenized path can then be used to easily identify all folders affected by a change to another folder. Updates to higher levels in the folder hierarchy could result in a large number of dependant folders needing to be updated, but if this is a reasonably rare event, it may be worth it as querying may be simpler and faster.