# How to include child aggregations into parent results?

**URL:** <https://discuss.elastic.co/t/how-to-include-child-aggregations-into-parent-results/104356>\
**Category:** Elasticsearch\
**Created:** [October 18, 2017, 8:56am UTC](https://discuss.elastic.co/t/how-to-include-child-aggregations-into-parent-results/104356 "2017-10-18T08:56:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![StefanGl](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@StefanGl](https://discuss.elastic.co/u/StefanGl)\
**Post date:** [October 18, 2017, 8:56am UTC](https://discuss.elastic.co/t/how-to-include-child-aggregations-into-parent-results/104356/1 "2017-10-18T08:56:39Z")

</div>

I've got the following parent/child mapping here:

```
{
  "mappings": {
    "parentBook": {
      "properties": {
        "ean": {
          "type": "keyword"
        },
        "title": {
          "type": "string"
        }
      }
    },
    "childBook": {
      "_parent": {
        "type": "parentBook" 
      },
      "properties": {
        "price": {
          "type": "float"
        },
        "condition": {
          "type": "string"
        },
        "quantity": {
          "type": "integer"
        }
      }
    }
  }
}

```

Then I have the following entries in the index:

parentBook

```
{
  "ean": "9783353002303",
  "title": "...any kind of a book..."
}

```

childrens for parent ean "9783353002303"

```
[
  {
    "price": "20",
    "condition": "new",
    "quantity": 3
  },
  {
    "price": "10",
    "condition": "used",
    "quantity": 1
  },
  {
    "price": "5",
    "condition": "used",
    "quantity": 1
  },
]

```

The goal is now to query for the parentBook with EAN, title, etc. and to get the results back like this:

```
EAN: 9783353002303
Title: ...any kind of a book...
   [1 offer new from 20 EUR] [2 offers used from 5 EUR]

```

I would like to show the aggregated values (minimum price per condition and count of child docs) just below the parent record and I would also be able to paginate the results.

I've already read about the Top Hit Aggregation but I always need to paginate through my grouped results.

---

<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:** [November 15, 2017, 8:56am UTC](https://discuss.elastic.co/t/how-to-include-child-aggregations-into-parent-results/104356/2 "2017-11-15T08:56:52Z")

</div>

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