# Aggregate Top Hits source elements

**URL:** <https://discuss.elastic.co/t/aggregate-top-hits-source-elements/105280>\
**Category:** Elasticsearch\
**Created:** [October 25, 2017, 5:10pm UTC](https://discuss.elastic.co/t/aggregate-top-hits-source-elements/105280 "2017-10-25T17:10:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shikha130vv](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@shikha130vv](https://discuss.elastic.co/u/shikha130vv)\
**Post date:** [October 25, 2017, 5:10pm UTC](https://discuss.elastic.co/t/aggregate-top-hits-source-elements/105280/1 "2017-10-25T17:10:41Z")

</div>

I am getting units\_agg = 0 . What am i doing wrong? I want to sum units in id\_agg

'{  
"size":1,

"aggs":  
{  
"article\_agg":  
{  
"terms":  
{  
"field":"articleid"  
},  
"aggs":  
{  
"sku\_agg":  
{  
"terms":  
{  
"field": "stockhistoryskuid"  
},  
"aggs":  
{

```
                "id_agg":
                {
                    "top_hits": 
                    {
                        "sort": 
                        {
                            "id": 
                            {
                                "order": "asc"
                            }
                        },
                        "_source": 
                        {
                            "includes": ["articleid", "units"]
                        },
                        "size" : 1
                    }
                },
                "units_agg":
                {
                    "sum":
                    {
                        "field":"id_agg.units"
                    }
                }
               

               
                
                
            }
        }
            
   }

```

}  
}}'

---

<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 22, 2017, 5:10pm UTC](https://discuss.elastic.co/t/aggregate-top-hits-source-elements/105280/2 "2017-11-22T17:10:56Z")

</div>

Closed on November 22, 2017, 5:10pm UTC

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