# 1 to n and join condition query

**URL:** <https://discuss.elastic.co/t/1-to-n-and-join-condition-query/14281>\
**Category:** Elasticsearch\
**Created:** [November 6, 2013, 4:30am UTC](https://discuss.elastic.co/t/1-to-n-and-join-condition-query/14281 "2013-11-06T04:30:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhuoming\_chen](https://avatars.discourse-cdn.com/v4/letter/z/e495f1/32.png) [@zhuoming\_chen](https://discuss.elastic.co/u/zhuoming_chen)\
**Post date:** [November 6, 2013, 4:30am UTC](https://discuss.elastic.co/t/1-to-n-and-join-condition-query/14281/1 "2013-11-06T04:30:33Z")

</div>

I have some data that are 1 to n relationship, what should I do to store  
the data and query them?  
Has anyone came to this situation ?  
e.g.  
I have the item model,but also, per item has many order,if I want to query  
both the item and order,it is difficult, I have learned about that the  
parent child relationship can solve this query,but it is not perfect, it  
can't sort on the child filed

--  
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:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 14, 2013, 10:04am UTC](https://discuss.elastic.co/t/1-to-n-and-join-condition-query/14281/2 "2013-11-14T10:04:22Z")

</div>

Hey,

there are several solutions to this problem:

1. Denormalize your data. This is highly dependent on your data upgrade  
patterns and can possibly result in a bad performance or complex  
application/update logic
2. Use Parent/Child to prevent heavy updates (because you can have a  
relation between employee and employer for example, but still index those  
entries as completely different documents)
3. Use nested documents to execute more complex queries, but still keep  
everything in one document

A couple of links (the blog post contains many links to the elasticsearch  
documentations)

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--Alex

On Wed, Nov 6, 2013 at 5:30 AM, zhuoming chen [zhuomingemail@gmail.com](mailto:zhuomingemail@gmail.com)wrote:

> I have some data that are 1 to n relationship, what should I do to store  
> the data and query them?  
> Has anyone came to this situation ?  
> e.g.  
> I have the item model,but also, per item has many order,if I want to query  
> both the item and order,it is difficult, I have learned about that the  
> parent child relationship can solve this query,but it is not perfect, it  
> can't sort on the child filed
> 
> --  
> 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).

--  
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:07am UTC](https://discuss.elastic.co/t/1-to-n-and-join-condition-query/14281/3 "2017-07-06T02:07:10Z")

</div>


