Parent-child and sorting on a child

Hi guys. If you create a parent-child relationship between 2 indices, is it
possible to sort the parent documents by one of its children's fields?

1 Like

No, you can't... . I assume you mean parent and child docs within the same
index (as there is no cross index, or cross shard relationships).

On Wed, Jan 11, 2012 at 11:20 PM, Nick Hoffman nick@deadorange.com wrote:

Hi guys. If you create a parent-child relationship between 2 indices, is
it possible to sort the parent documents by one of its children's fields?

On Thursday, 12 January 2012 05:46:08 UTC-5, kimchy wrote:

No, you can't... . I assume you mean parent and child docs within the same
index (as there is no cross index, or cross shard relationships).

That's what I meant. Thanks for clarifying it for me, mate.

So is this the only way to sort parent docs by a child doc's field?

  1. Search ES for the matching child docs, sorted on the desired field.

  2. In my application, figure out which parent docs each child doc relates
    to.

Thanks again for your help, Shay. It's really helpful and valuable.
Nick

Bump =)

On Thursday, 12 January 2012 11:24:42 UTC-5, Nick Hoffman wrote:

On Thursday, 12 January 2012 05:46:08 UTC-5, kimchy wrote:

No, you can't... . I assume you mean parent and child docs within the
same index (as there is no cross index, or cross shard relationships).

That's what I meant. Thanks for clarifying it for me, mate.

So is this the only way to sort parent docs by a child doc's field?

  1. Search ES for the matching child docs, sorted on the desired field.

  2. In my application, figure out which parent docs each child doc relates
    to.

Thanks again for your help, Shay. It's really helpful and valuable.
Nick

Yea, thats a way to solve it. Note you can get the parent id from the child
by asking for _parent field.

On Thu, Jan 12, 2012 at 6:24 PM, Nick Hoffman nick@deadorange.com wrote:

On Thursday, 12 January 2012 05:46:08 UTC-5, kimchy wrote:

No, you can't... . I assume you mean parent and child docs within the
same index (as there is no cross index, or cross shard relationships).

That's what I meant. Thanks for clarifying it for me, mate.

So is this the only way to sort parent docs by a child doc's field?

  1. Search ES for the matching child docs, sorted on the desired field.

  2. In my application, figure out which parent docs each child doc relates
    to.

Thanks again for your help, Shay. It's really helpful and valuable.
Nick

On Tuesday, 17 January 2012 04:26:59 UTC-5, kimchy wrote:

Yea, thats a way to solve it. Note you can get the parent id from the
child by asking for _parent field.

Ah, that makes life much easier, actually. Thanks, Shay.

We would really like to be able to do this kind of sorting. We do
filtering on a Child document and sorting on a field in the Parent, for
potential results that would be much too large to sort in the application.
(E.g., hundreds of pages of thousands of docs, sorted by ES, and only
presenting the top docs.) The Child record actually has the field we'd
like to sort by, and we copy this field to the parent. This means the
parents are often out of sync with the child, and so the sort results are
misleading when the parent and child are out of sync. Even if it was a
relatively expensive operation, it would be extremely useful to be able to
give sorted results of a Parent based on a field in a Child.

James

On Thursday, January 12, 2012 3:46:08 AM UTC-7, kimchy wrote:

No, you can't... . I assume you mean parent and child docs within the same
index (as there is no cross index, or cross shard relationships).

On Wed, Jan 11, 2012 at 11:20 PM, Nick Hoffman nick@deadorange.comwrote:

Hi guys. If you create a parent-child relationship between 2 indices, is
it possible to sort the parent documents by one of its children's fields?

Hi all --

I was just curious if this was still impossible since it's been many months
since the last update. I have the same need in my application except a
further request since I'm returning two types in my sorted list - one of
which has children objects and one of which that does not but need to sort
consistently across both top level objects.

I opened a thread here to ask about using a custom score via a script to
achieve the same thing. I'm not sure if that is a possibility:
https://groups.google.com/forum/?fromgroups=#!topic/elasticsearch/KMmEOuc9Ce0

thanks

On Thursday, July 19, 2012 1:45:28 AM UTC-5, James McGill wrote:

We would really like to be able to do this kind of sorting. We do
filtering on a Child document and sorting on a field in the Parent, for
potential results that would be much too large to sort in the application.
(E.g., hundreds of pages of thousands of docs, sorted by ES, and only
presenting the top docs.) The Child record actually has the field we'd
like to sort by, and we copy this field to the parent. This means the
parents are often out of sync with the child, and so the sort results are
misleading when the parent and child are out of sync. Even if it was a
relatively expensive operation, it would be extremely useful to be able to
give sorted results of a Parent based on a field in a Child.

James

On Thursday, January 12, 2012 3:46:08 AM UTC-7, kimchy wrote:

No, you can't... . I assume you mean parent and child docs within the
same index (as there is no cross index, or cross shard relationships).

On Wed, Jan 11, 2012 at 11:20 PM, Nick Hoffman <ni...@deadorange.com<javascript:>

wrote:

Hi guys. If you create a parent-child relationship between 2 indices, is
it possible to sort the parent documents by one of its children's fields?

--
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.

Any changes in ES 2.x version related to child field based sorting?

Is it still not possible?

AFAIK still the same - https://github.com/elastic/elasticsearch/issues/2917

Hey Guys - i'm having similar issues with parent sorting based on child field.
Using Elastic 5.3
i see on the has_child page it says to use script_score but it's wont work for text and date fields? and how do we specify the order? any ideas?