# Can the max-metric aggs return any fields i want of the doc which is the max in bucket

**URL:** <https://discuss.elastic.co/t/can-the-max-metric-aggs-return-any-fields-i-want-of-the-doc-which-is-the-max-in-bucket/40554>\
**Category:** Elasticsearch\
**Created:** [January 30, 2016, 12:25pm UTC](https://discuss.elastic.co/t/can-the-max-metric-aggs-return-any-fields-i-want-of-the-doc-which-is-the-max-in-bucket/40554 "2016-01-30T12:25:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Red](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@Red](https://discuss.elastic.co/u/Red)\
**Post date:** [January 30, 2016, 12:25pm UTC](https://discuss.elastic.co/t/can-the-max-metric-aggs-return-any-fields-i-want-of-the-doc-which-is-the-max-in-bucket/40554/1 "2016-01-30T12:25:48Z")

</div>

i want to retrieval the sku id in the doc which has sold most.  
i need to use aggs to aggs the spu, and find out the best sold sku.  
here is my code

```
          "size":0,
          "aggregations": {
          "spu_group": {
                "terms": {
                  "field": "product_id",
                  "size": 4,
                  "order" : {"sum_sku_sell_num": "desc"}
                },
                "aggregations": {
                    "sum_sku_sell_num":{
                        "sum": {
                            "field": "sku_sell_num"
                        }
                    },
                    "max_sku_sell_num_sku":{
                       "top_hits": {
                            "sort":[
                                {
                                    "sku_sell_num": {
                                        "order": "desc",
                                        "missing": 0
                                    }
                                }
                            ],
                            "_source": {
                                "include": [
                                    "sku_id"
                                ]
                            },
                            "from": 0,
                            "size": 1
                        }
                    }
                }
            }
          }

```

top\_hits can satisfy my request. but i think its a little complex, and max-metric is simple to use, but i dont know how to return any info of the doc.

and top\_hits may have low performace than max-metric, metric aggs doesnot create bucket, it only calculate?  
although the top\_hits is a metric-aggs, it will create and sort the docs if i want to get the max doc.

i may use the top\_hits only if it behaves like the max-metric when i set the size of top\_hits to 1 .  
may i do this??????

---

<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:** [July 5, 2017, 11:20pm UTC](https://discuss.elastic.co/t/can-the-max-metric-aggs-return-any-fields-i-want-of-the-doc-which-is-the-max-in-bucket/40554/2 "2017-07-05T23:20:10Z")

</div>


