Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting parents on property of inner hits #1504

Closed
MichelBrinckman opened this issue Jul 30, 2015 · 1 comment
Closed

Sorting parents on property of inner hits #1504

MichelBrinckman opened this issue Jul 30, 2015 · 1 comment

Comments

@MichelBrinckman
Copy link

We have an index with two types, companies and persons. Now we have a haschild query on companies, to be able to find companies that contain names of specific persons. For example, give me all company types that have a child with the name 'Jansen'.

Now I want to sort those results (which consists of the parents of type company) on the firstnames of the persons working for that company.

The following query does not sort my companies, based on the inner_hits:

{
  "query": {
    "has_child": {
      "type": "employee",
      "inner_hits" : {},
      "query": {
        "term" : {"firstname" : "jan"}
      }
    }
  },
  "sort": [{"employee.firstname" : "desc"}]
}

Sorting INSIDE the inner hits works fine:

{
  "query": {
    "has_child": {
      "type": "employee",
      "inner_hits" : {  "sort": [{"lastname" : "asc"}]},
      "query": {
        "term" : {"firstname" : "jan"}
      }
    }
  }
}

and:

{
  "query": {
    "has_child": {
      "type": "employee",
      "inner_hits" : {},
      "query": {
        "term" : {"firstname" : "jan"}
      }
    }
  },
  "sort": [{"revenue" : "desc"}]
}

sorts the companies based on revenue just fine. I understand the last one is a property of the parent , but how do I sort the parents based on a property of the child?

@Mpdreamz
Copy link
Member

Mpdreamz commented Aug 2, 2015

As far as I know this is still an open feature request in elasticsearch itself:

elastic/elasticsearch#2917

And the only workaround for now is to duplicate the data you want to sort on on the company object, although I can imagine this is not always possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants