# Aggregation on Nested Field of child document with nested aggregation on parent document

**URL:** https://discuss.elastic.co/t/aggregation-on-nested-field-of-child-document-with-nested-aggregation-on-parent-document/208642
**Category:** Elasticsearch
**Created:** [November 20, 2019, 7:38am UTC](https://discuss.elastic.co/t/aggregation-on-nested-field-of-child-document-with-nested-aggregation-on-parent-document/208642 "2019-11-20T07:38:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Animesh\_singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/animesh_singh/32/46768_2.png) [@Animesh\_singh](https://discuss.elastic.co/u/Animesh_singh)
#### Post date: [November 20, 2019, 7:38am UTC](https://discuss.elastic.co/t/aggregation-on-nested-field-of-child-document-with-nested-aggregation-on-parent-document/208642/1 "2019-11-20T07:38:00Z")

</div>

Hey , Can anyone help me with this , the buckets are not formed by elastic search .  
What i want to is -  
Aggregate on a nested field present in child document[object.name] and further aggregate them their parent documents to get the doc counts of parent .

Mapping -----------\>

```
 "album" : {
        "properties" : {
          "frames" : {
            "type" : "long",
            "index" : false,
            "store" : true
          },
          "network" : {
            "type" : "keyword",
            "store" : true
          }
      }
    }
  "object" : {
        "type" : "nested",
        "properties" : {
          "confidence" : {
            "type" : "long",
            "store" : true
          },
          "height" : {
            "type" : "long",
            "index" : false,
            "store" : true
          },
          "name" : {
            "type" : "text",
            "store" : true,
            "norms" : false,
            "fields" : {
              "keyword" : {
                "type" : "keyword"
              }
            },
            "analyzer" : "shingle_analyzer"
          }
}
      "my_join_field" : {
        "type" : "join",
        "eager_global_ordinals" : true,
        "relations" : {
          "video" : "frame"
        }
      },

```

}

=======================================================================

Child Document ----------\>

```
 "_source" : {
  "object" : [
        {
          "confidence" : 89.78,
          "name" : "Crowd",
          "recog_object_types" : [
            "OBJECT"
          ]
        },
        {
          "confidence" : 59.35,
          "name" : "Audience",
          "recog_object_types" : [
            "OBJECT"
          ]
        }
]
 "my_join_field" : {
        "name" : "frame",
        "parent" : "fc6ac4b6-600d-41c3-8de0-1950d794c246"
      }
 }

```

===============================================================================

Parent Document ---------\>

```
"_source" : {
"id_es" : "fc6ac4b6-600d-41c3-8de0-1950d794c246",
"album" : {
  "uuid" : "4f810024-972b-4ee9-83db-aa6e1ba89760",
  "remote_id" : "gkr57P0fwbI",
  "network" : "YOUTUBE"
},
  "my_join_field" : "video"
 }

```

===============================================================================

Query I am Executing--------\>

```
GET video-1/_search
{
 "size": 0, 
 "aggs": {
 "object": {
  "nested": {
    "path": "object"
  }, 
  "aggs": {
    "object":{
  "terms": {
    "field": "object.name.keyword",
    "size": 20
  },
  "aggs": {
  "video": {
    "parent": {
      "type": "frame"
    },
    "aggs": {
      "netowrk": {
          "terms": {
            "field": "album.network",
            "size": 10
          }
      }
    }
  } 
}
  }
  }
}

```

}

===============================================================================

Results -------------------- \> No buckets Are Formed

```
 "aggregations" : {
 "object" : {
  "doc_count" : 22257571,
  "object" : {
    "doc_count_error_upper_bound" : 115666,
    "sum_other_doc_count" : 14641596,
    "buckets" : [
      {
        "key" : "Human",
        "doc_count" : 1042039,
        "video" : {
          "doc_count" : 0,
          "netowrk" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : []
          }
        }
      },
      {
        "key" : "Person",
        "doc_count" : 1000239,
        "video" : {
          "doc_count" : 0,
          "netowrk" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : []
          }
        }
      },
      {
        "key" : "People",
        "doc_count" : 934566,
        "video" : {
          "doc_count" : 0,
          "netowrk" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : []
          }
        }

```

==============================================================================  
Can anyone help me with this , elastic search is not making any bucket of parent documents if i am aggregating with nested fields in child document but if use non nested field of child document it works fine .

---

<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: [December 18, 2019, 7:38am UTC](https://discuss.elastic.co/t/aggregation-on-nested-field-of-child-document-with-nested-aggregation-on-parent-document/208642/2 "2019-12-18T07:38:12Z")

</div>

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