# Sorting parents on property of inner hits

**URL:** <https://discuss.elastic.co/t/sorting-parents-on-property-of-inner-hits/128969>\
**Category:** Elasticsearch\
**Created:** [April 21, 2018, 1:21pm UTC](https://discuss.elastic.co/t/sorting-parents-on-property-of-inner-hits/128969 "2018-04-21T13:21:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Syed\_ali\_abbas\_shah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/syed_ali_abbas_shah/32/30053_2.png) [@Syed\_ali\_abbas\_shah](https://discuss.elastic.co/u/Syed_ali_abbas_shah)\
**Post date:** [April 21, 2018, 1:21pm UTC](https://discuss.elastic.co/t/sorting-parents-on-property-of-inner-hits/128969/1 "2018-04-21T13:21:19Z")

</div>

We have an index with Parent and Child Model, users and posts. Now we have a has\_child query on posts, to be able to sort users based on desc order of post creation. in other words I need the user on top which has very latest post.

Here is my mapping

```auto
{
    "properties":{
          "id": {
            "type": "keyword"
          },
         "content":{
            "type": "text"
          },
          "created_at": {
            "type": "date"
        },
          "join_type": {
            "type": "join",
            "relations": {
                "user": [
                    "post",
                ],
            }
        }
    }
}

```

The following query does not sort my users, based on the inner\_hits:

```auto
{
  "query": {
    "has_child": {
      "type": "post",
      "inner_hits" : {},
      "query": {
        "match" : {"content" : "test"}
      }
    }
  },
  "sort": [{"post.created_at" : "desc"}]
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 19, 2018, 1:21pm UTC](https://discuss.elastic.co/t/sorting-parents-on-property-of-inner-hits/128969/2 "2018-05-19T13:21:48Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
