# Query the sum of a filtered subset of nested documents

**URL:** https://discuss.elastic.co/t/query-the-sum-of-a-filtered-subset-of-nested-documents/183512
**Category:** Elasticsearch
**Created:** [May 30, 2019, 11:23am UTC](https://discuss.elastic.co/t/query-the-sum-of-a-filtered-subset-of-nested-documents/183512 "2019-05-30T11:23:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Kazim\_Zaidi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kazim_zaidi/32/47149_2.png) [@Kazim\_Zaidi](https://discuss.elastic.co/u/Kazim_Zaidi)
#### Post date: [May 30, 2019, 11:23am UTC](https://discuss.elastic.co/t/query-the-sum-of-a-filtered-subset-of-nested-documents/183512/1 "2019-05-30T11:23:24Z")

</div>

Consider a document like this:

```auto
    {
      title: "I love ice cream!"
      comments: [
        {
          body: "me too!",
          reaction: 'positive',
          likes: 20
        },
        {
          body: "huh!",
          reaction: 'sarcastic',
          likes: 5
        }
      ]
    }

```

The comments is a field of `nested` type.

How can elastic answer this:  
Give me all posts, where the total sum of likes on "sarcastic" comments is greater than 100.  
I'm open to any other way of modelling data which helps answer such queries.

---

<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: [June 27, 2019, 11:23am UTC](https://discuss.elastic.co/t/query-the-sum-of-a-filtered-subset-of-nested-documents/183512/2 "2019-06-27T11:23:26Z")

</div>

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