# Document design for querying related documents efficiently

**URL:** <https://discuss.elastic.co/t/document-design-for-querying-related-documents-efficiently/12611>\
**Category:** Elasticsearch\
**Created:** [July 2, 2013, 2:46am UTC](https://discuss.elastic.co/t/document-design-for-querying-related-documents-efficiently/12611 "2013-07-02T02:46:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nwood888](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@nwood888](https://discuss.elastic.co/u/nwood888)\
**Post date:** [July 2, 2013, 2:46am UTC](https://discuss.elastic.co/t/document-design-for-querying-related-documents-efficiently/12611/1 "2013-07-02T02:46:15Z")

</div>

I've looked into the "Parent Field" but from my understanding it won't work  
for what I'm trying to do, but I mention it because it's very similar. The  
use case is a reporting system where we need to have some access control.  
Consider these 3 documents:

parent\_type\_1  
parent\_type\_2  
child\_type\_1

The query needs to pull all of the child records where the user is listed  
as an owner in either of the parent records.

Both parent types have a field called "owners" that list the users that  
should have access to the parent records.

The child type has a reference to one or two parent types. I believe that  
if it only referenced a single parent type, the "Parent Field" would be the  
perfect solution.

We're considering just adding an extra step in the application layer to  
copy the owners from parent to child whenever a parent is modified, but  
this feels clunky.

We're using routing to ensure that related parent and child records will  
always be on the same shard if that makes a difference.

Any suggestions would be much appreciated.

Nick

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:28am UTC](https://discuss.elastic.co/t/document-design-for-querying-related-documents-efficiently/12611/2 "2017-07-06T02:28:44Z")

</div>

Closed on July 6, 2017, 2:28am UTC


