# How to multiply top-terms-aggregation by document value?

**URL:** <https://discuss.elastic.co/t/how-to-multiply-top-terms-aggregation-by-document-value/79137>\
**Category:** Elasticsearch\
**Created:** [March 18, 2017, 2:15pm UTC](https://discuss.elastic.co/t/how-to-multiply-top-terms-aggregation-by-document-value/79137 "2017-03-18T14:15:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luizguilhermefr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luizguilhermefr/32/16477_2.png) [@luizguilhermefr](https://discuss.elastic.co/u/luizguilhermefr)\
**Post date:** [March 18, 2017, 2:15pm UTC](https://discuss.elastic.co/t/how-to-multiply-top-terms-aggregation-by-document-value/79137/1 "2017-03-18T14:15:14Z")

</div>

Hi, I want to top term values like this:

```
{
   "products":[
      {
         "identifier":1,
         "name":"Foo",
         "quantity":2
      },
      {
         "identifier":2,
         "name":"Bar",
         "quantity":3
      }
   ]
}

```

But instead of considering simply the times each record occurs, I want to query the count times quantity field, like considering the identifier 2 product to 3 instead of one in the above example.

How could I do it?

My current query is:

```
{
   "size":0,
   "aggs":{
      "products":{
         "nested":{
            "path":"products"
         },
         "aggs":{
            "top-terms-aggregation":{
               "terms":{
                  "field":"products.identifier",
                  "size":10
               }
            }
         }
      }
   }
}
```

---

<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 15, 2017, 2:16pm UTC](https://discuss.elastic.co/t/how-to-multiply-top-terms-aggregation-by-document-value/79137/2 "2017-04-15T14:16:14Z")

</div>

Closed on April 15, 2017, 2:16pm UTC

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