Polymorphic parent/child relationships


(domizio) #1

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? :slight_smile:


(Shay Banon) #2

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? :slight_smile:


(system) #3