Parent indexes with multiple children


(frazer) #1

I have a couple of questions regarding parent child mappings and multi
children searching.

  1. I know the following structure/mapping works for parent child:
    http://localhost:9200/blogs/blog
    http://localhost:9200/blogs/blog_comments
    http://localhost:9200/blogs/blog_tags

The above was based on this gist (https://gist.github.com/758398)

However the client I am using generates the indexes in the following
manner
http://localhost:9200/blogs/blog
http://localhost:9200/blog_comments/blog_comment
http://localhost:9200/blog_tags/blog_tag

I know the child needs to be in the same shard as the parent (or is
recommended). I just wanted to know is there any way to route the
indexes in the second example(maybe in the mapping) to create the
parent child relationships?

  1. Does a parent index support searching on multiple children, would
    something like this work and would this be the most efficient way to
    search across multiple children?

curl -XGET 'http://localhost:9200/blogs/_search' -d '{
"query" : {
"filtered" : {
"query" : {"term" : {"blog_site_id" : "1"} },
"filter" : {
"or" : [
{
"has_child" : {
"type" : "comment",
"query" :{"term" : {"body" : "some text"} }
}
},{
"has_child" : {
"type" : "tags",
"query" :{"term" : {"tag_name" : "some text"} }
}
}]
}
}
}
}'

  1. Anyone know if there are plans to support returning the child docs
    and/or a has_parent query option?

Thanks

Frazer


(Shay Banon) #2

On Tuesday, January 25, 2011 at 4:06 PM, frazer wrote:

I have a couple of questions regarding parent child mappings and multi
children searching.

  1. I know the following structure/mapping works for parent child:
    http://localhost:9200/blogs/blog
    http://localhost:9200/blogs/blog_comments
    http://localhost:9200/blogs/blog_tags

The above was based on this gist (https://gist.github.com/758398)

However the client I am using generates the indexes in the following
manner
http://localhost:9200/blogs/blog
http://localhost:9200/blog_comments/blog_comment
http://localhost:9200/blog_tags/blog_tag

I know the child needs to be in the same shard as the parent (or is
recommended).

Its not recommended, its a requirement. You can't actually do parent child relationship without it being the case.

I just wanted to know is there any way to route the
indexes in the second example(maybe in the mapping) to create the
parent child relationships?

No, it only works when the parent and the child are within the same shard.

  1. Does a parent index support searching on multiple children, would
    something like this work and would this be the most efficient way to
    search across multiple children?

Yep, this should work.

curl -XGET 'http://localhost:9200/blogs/_search' -d '{
"query" : {
"filtered" : {
"query" : {"term" : {"blog_site_id" : "1"} },
"filter" : {
"or" : [
{
"has_child" : {
"type" : "comment",
"query" :{"term" : {"body" : "some text"} }
}
},{
"has_child" : {
"type" : "tags",
"query" :{"term" : {"tag_name" : "some text"} }
}
}]
}
}
}
}'

  1. Anyone know if there are plans to support returning the child docs
    and/or a has_parent query option?

Thanks

Frazer


(frazer) #3

Thanks Shay

On Jan 25, 1:13 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

On Tuesday, January 25, 2011 at 4:06 PM, frazer wrote:

I have a couple of questions regarding parent child mappings and multi
children searching.

  1. I know the following structure/mapping works for parent child:
    http://localhost:9200/blogs/blog
    http://localhost:9200/blogs/blog_comments
    http://localhost:9200/blogs/blog_tags

The above was based on this gist (https://gist.github.com/758398)

However the client I am using generates the indexes in the following
manner
http://localhost:9200/blogs/blog
http://localhost:9200/blog_comments/blog_comment
http://localhost:9200/blog_tags/blog_tag

I know the child needs to be in the same shard as the parent (or is
recommended).

Its not recommended, its a requirement. You can't actually do parent child relationship without it being the case.

I just wanted to know is there any way to route the
indexes in the second example(maybe in the mapping) to create the
parent child relationships?

No, it only works when the parent and the child are within the same shard.

  1. Does a parent index support searching on multiple children, would
    something like this work and would this be the most efficient way to
    search across multiple children?

Yep, this should work.

curl -XGET 'http://localhost:9200/blogs/_search'-d '{
"query" : {
"filtered" : {
"query" : {"term" : {"blog_site_id" : "1"} },
"filter" : {
"or" : [
{
"has_child" : {
"type" : "comment",
"query" :{"term" : {"body" : "some text"} }
}
},{
"has_child" : {
"type" : "tags",
"query" :{"term" : {"tag_name" : "some text"} }
}
}]
}
}
}
}'

  1. Anyone know if there are plans to support returning the child docs
    and/or a has_parent query option?

Thanks

Frazer


(system) #4