How to get childs child in a single Query

I'm not sure if this is something that is doable in a single Query
Here is the gist

Essentially I have following relationship

Parent (catentry) - one to many child (attributes) - one to many child
(attrvalues)

For a given parent entry I want to get all associated childs (attributes)
and all child documents of parent attributes? is is doable in a single
Query?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

On 18.05.2013 03:07, Hariharan Vadivelu wrote:

For a given parent entry I want to get all associated childs (attributes)
and all child documents of parent attributes? is is doable in a single
Query?

Hi Hariharan,

as far as I know, it's not. I think you'll need two round trips to get
parents and children. And for their children again one more.

If you only need the child documents for a limited number of parents,
you can use a multi search request to gather the corresponding children:

This is how I solved a simpler problem with just one additional level
(parent/child), where I needed the child docs only for the top-n parent
docs to be displayed. First search on parents, then take the top-n
parents and build a multi search over the child docs with a term query
on the "_parent" field for each parent doc. The multi search response
contains the list of child docs in the same order, so it's easy to map
them back to the list of parent docs.

In my scenario it's fast enough, though it takes two round trips instead
of just one. Also, if you need to get the child docs of a large list of
parent docs, this is probably not the way to go, I guess. Maybe somebody
comes up with a more elegant solution for that.

Best regards,
Hannes

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Actually after I included routing to both child and child's child and run following Query I get everything associated to top level parent, is this an option to get all the sub documents associated to a top level parent?

curl -XPOST 'http://localhost:9200/products/_search?pretty=true' -d '{
"query": {
"filtered": {
"query": {
"term": {"catentry_id" :"EI01Y" }
}
}
}
}'

On Saturday, May 18, 2013 4:56:33 AM UTC-5, Hannes Korte wrote:

On 18.05.2013 03:07, Hariharan Vadivelu wrote:

For a given parent entry I want to get all associated childs
(attributes)
and all child documents of parent attributes? is is doable in a single
Query?

Hi Hariharan,

as far as I know, it's not. I think you'll need two round trips to get
parents and children. And for their children again one more.

If you only need the child documents for a limited number of parents,
you can use a multi search request to gather the corresponding children:
http://www.elasticsearch.org/guide/reference/api/multi-search/

This is how I solved a simpler problem with just one additional level
(parent/child), where I needed the child docs only for the top-n parent
docs to be displayed. First search on parents, then take the top-n
parents and build a multi search over the child docs with a term query
on the "_parent" field for each parent doc. The multi search response
contains the list of child docs in the same order, so it's easy to map
them back to the list of parent docs.

In my scenario it's fast enough, though it takes two round trips instead
of just one. Also, if you need to get the child docs of a large list of
parent docs, this is probably not the way to go, I guess. Maybe somebody
comes up with a more elegant solution for that.

Best regards,
Hannes

--
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.
For more options, visit https://groups.google.com/groups/opt_out.