# Polymorphic parent/child relationships

**URL:** https://discuss.elastic.co/t/polymorphic-parent-child-relationships/6961
**Category:** Elasticsearch
**Created:** [March 9, 2012, 2:59pm UTC](https://discuss.elastic.co/t/polymorphic-parent-child-relationships/6961 "2012-03-09T14:59:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![domizio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/domizio/32/2530_2.png) [@domizio](https://discuss.elastic.co/u/domizio)
#### Post date: [March 9, 2012, 2:59pm UTC](https://discuss.elastic.co/t/polymorphic-parent-child-relationships/6961/1 "2012-03-09T14:59:31Z")

</div>

Hi,  
I am working on an app that has a few polymorphic associations. For  
example:

Comment may be child of Blog or Review, so when I search in the  
comment type I would like to get the parent document of the query run  
against the comment.content, that may be a blog or a review.

I see that the mapping ties the child to a fixed parent type, so that  
doesn't seem to be possible at this time. I am missing something? Is  
there any way to achieve that?

I would like to be able to index the child documents as:

curl -XPUT localhost:9200/app\_index/comment/1001?  
parent\_type=blog&parent\_id=1111 -d '  
{  
"content" : "this blog rocks"  
}  
'

curl -XPUT localhost:9200/app\_index/comment/1002?  
parent\_type=review&parent\_id=2222 -d '  
{  
"content" : "this review is fair"  
}  
'

In practice what I would like ES to have is the possibility to link a  
child to any type of parent, explicitly, when the child is indexed. Is  
that possible? Will it be possible? 🙂

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [March 9, 2012, 7:10pm UTC](https://discuss.elastic.co/t/polymorphic-parent-child-relationships/6961/2 "2012-03-09T19:10:09Z")

</div>

No, its not possible and the mapping from a child _type_ is constant to a parent type.

On Friday, March 9, 2012 at 4:59 PM, Domizio Demichelis wrote:

> Hi,  
> I am working on an app that has a few polymorphic associations. For  
> example:
> 
> Comment may be child of Blog or Review, so when I search in the  
> comment type I would like to get the parent document of the query run  
> against the comment.content, that may be a blog or a review.
> 
> I see that the mapping ties the child to a fixed parent type, so that  
> doesn't seem to be possible at this time. I am missing something? Is  
> there any way to achieve that?
> 
> I would like to be able to index the child documents as:
> 
> curl -XPUT localhost:9200/app\_index/comment/1001?  
> parent\_type=blog&parent\_id=1111 -d '  
> {  
> "content" : "this blog rocks"  
> }  
> '
> 
> curl -XPUT localhost:9200/app\_index/comment/1002?  
> parent\_type=review&parent\_id=2222 -d '  
> {  
> "content" : "this review is fair"  
> }  
> '
> 
> In practice what I would like ES to have is the possibility to link a  
> child to any type of parent, explicitly, when the child is indexed. Is  
> that possible? Will it be 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: [July 6, 2017, 3:36am UTC](https://discuss.elastic.co/t/polymorphic-parent-child-relationships/6961/3 "2017-07-06T03:36:30Z")

</div>


