Sorting on Parent/Child attributes


I'm looking for a solution to a problem I am having. Lets say I have 2
types Person and Pet in an index called customers.


I would like to query/filter on fields in both person and pet in order to
retrieve people and their associated pet. Additionally, I need to sort on
a field that could be in either person or pet.

For example, retrieve all people/pets that have wildcard person.firstname
'ave' and pet.type wildcard 'terrier' and sort on Or
wildcard search on person.SSN = '55' and'mister' and sort on

I currently have a solution where I search/sort on people or pet based on
the sort that I am using. I use a hasChild/hasParent to manage the fields
that are on the 'other' type. Then I use an id field to retrieve the
entities of the other type. So, if I have a sort on personfirstname, I
query on person and child (pet) and sort on person.firstname, then use the
accounts to retrieve the pets (by account) in another query. This is not
ideal because it is ugly and I suspect difficult to maintain if this
query's requirements change in the future.

I suspect that I can do a query at the 'customers' level and do 'type'
queries on the fields that I need for person and pet. Similar to this:

However, I'm not sure how I would implement the sort. I suspect that I
could use a custom scoring script, but I am not sure how I would score text

Any thoughts?

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
To view this discussion on the web visit
For more options, visit