# Sorting document based on parent attributes

**URL:** <https://discuss.elastic.co/t/sorting-document-based-on-parent-attributes/72817>\
**Category:** Elasticsearch\
**Created:** [January 25, 2017, 9:25pm UTC](https://discuss.elastic.co/t/sorting-document-based-on-parent-attributes/72817 "2017-01-25T21:25:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik\_Miller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/erik_miller/32/14913_2.png) [@Erik\_Miller](https://discuss.elastic.co/u/Erik_Miller)\
**Post date:** [January 25, 2017, 9:25pm UTC](https://discuss.elastic.co/t/sorting-document-based-on-parent-attributes/72817/1 "2017-01-25T21:25:56Z")

</div>

I'm having trouble returning documents in the expected order. It relates to television listings. The child document is the timeslot (a tv station and time) and the parent is the program that would be on the station at that time.

I'm using es 2.3 and scripting is turned off on the cluster, so that is not an option.

The query so far is just querying for all timeslots and attempting to sort on the programId.

My query is below...

```
{
  "filter": {
  "has_parent": {
  "parent_type": "program",
  "score_mode": "min",
  "query": {
    "function_score": {
      "functions": [
        {
          "field_value_factor": {
            "factor": 1
            "field": "programId"
          }
        }
      ],
      "query": {}
    }
  },
  "inner_hits":{"_source":["programId"]}
}
 },
 "sort": "_score",
  "size":20,
  "_source":["programId"]
}
```

---

<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:** [February 22, 2017, 9:26pm UTC](https://discuss.elastic.co/t/sorting-document-based-on-parent-attributes/72817/2 "2017-02-22T21:26:21Z")

</div>

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