# Parent/Child Aggregation ordering problem ES 7.6

**URL:** <https://discuss.elastic.co/t/parent-child-aggregation-ordering-problem-es-7-6/223066>\
**Category:** Elasticsearch\
**Created:** [March 11, 2020, 8:12am UTC](https://discuss.elastic.co/t/parent-child-aggregation-ordering-problem-es-7-6/223066 "2020-03-11T08:12:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dizzzyroma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dizzzyroma/32/64191_2.png) [@dizzzyroma](https://discuss.elastic.co/u/dizzzyroma)\
**Post date:** [March 11, 2020, 8:12am UTC](https://discuss.elastic.co/t/parent-child-aggregation-ordering-problem-es-7-6/223066/1 "2020-03-11T08:12:03Z")

</div>

Hi All,  
We try to migrate to ES 7.X from ES 5.3 and found next problem:  
In ES 7.6.1 Aggregation ordering path not working when we try to aggregate parent/child documents  
In ES 5.3 Its working fine

ES 7.6.1 Example:

```
PUT my_index
{
  "mappings": {
    "properties": {
        "employer_id": {
          "type": "integer"
        },
         "price": {
          "type": "integer"
        },
       "join_field": { 
        "type": "join",
        "relations": {
          "order": "item" 
        }
      }
    }
  }
}

GET my_index/_search
{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "relation": "order"
              }
            }
          ]
        }
      }
    }
  },
  "aggs": {
    "employer": {
      "terms": {
        "field": "employer_id",
        "size": "50",
        "order": {
          "child_join>price_sum": "desc"
        }
      },
      "aggs": {
        "child_join": {
          "children": {
            "type": "item"
          },
          "aggs": {
            "price_sum": {
              "sum": {
                "field": "price"
              }
            }
          }
        }
      }
    }
  }
}

```

Response:

```
{
  "error": {
    "root_cause": [
      {
        "type": "aggregation_execution_exception",
        "reason": "Invalid aggregation order path [child_join>price_sum]. Buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end. Sub-path [child_join] points to non single-bucket aggregation"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "my_index",
        "node": "MMgye6_eSdqPGUc6buwxLQ",
        "reason": {
          "type": "aggregation_execution_exception",
          "reason": "Invalid aggregation order path [child_join>price_sum]. Buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end. Sub-path [child_join] points to non single-bucket aggregation"
        }
      }
    ]
  },
  "status": 500
}

```

ES 5.3 Example works fine:

```
PUT my_index
{
  "mappings": {
    "order": {
      "properties": {
        "employer_id": {
          "type": "integer"
        }
      }
    },
    "item": {
      "properties": {
        "price": {
          "type": "integer"
        }
      },
      "_parent": {
        "type": "order"
      }
    }
  }
}

GET my_index/order/_search
{
  "aggs": {
    "employer": {
      "terms": {
        "field": "employer_id",
        "size": "50",
        "order": {
          "child_join>price_sum": "desc"
        }
      },
      "aggs": {
        "child_join": {
          "children": {
            "type": "item"
          },
          "aggs": {
            "price_sum": {
              "sum": {
                "field": "price"
              }
            }
          }
        }
      }
    }
  }
}

```

Any idea whats wrong or I am doing something wrong?

---

<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:** [April 8, 2020, 8:22am UTC](https://discuss.elastic.co/t/parent-child-aggregation-ordering-problem-es-7-6/223066/2 "2020-04-08T08:22:20Z")

</div>

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