# Sum one or more fields with date aggregation

**URL:** <https://discuss.elastic.co/t/sum-one-or-more-fields-with-date-aggregation/145698>\
**Category:** Elasticsearch\
**Created:** [August 23, 2018, 10:14am UTC](https://discuss.elastic.co/t/sum-one-or-more-fields-with-date-aggregation/145698 "2018-08-23T10:14:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patricia\_Narvasa](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@Patricia\_Narvasa](https://discuss.elastic.co/u/Patricia_Narvasa)\
**Post date:** [August 23, 2018, 10:14am UTC](https://discuss.elastic.co/t/sum-one-or-more-fields-with-date-aggregation/145698/1 "2018-08-23T10:14:17Z")

</div>

Hi all,

can you please help me on this. I have this following data:

1. **timestamp** : 2018-01-01T10:30:00+08:00 , **countSubject** : 3 , **countExtra** : 5
2. **timestamp** : 2018-01-11T10:30:00+08:00 , **countSubject** : 4 , **countExtra** : 5
3. **timestamp** : 2018-03-01T10:30:00+08:00 , **countSubject** : 6 , **countExtra** : 5
4. **timestamp** : 2018-02-29T10:30:00+08:00 , **countSubject** : 8 , **countExtra** : 5

I just want to clarify if I can have a query that gets the sum of countSubject, sum of countExtra from 2018-01-01 to 2018-05-01 with monthly interval

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [September 2, 2018, 11:28am UTC](https://discuss.elastic.co/t/sum-one-or-more-fields-with-date-aggregation/145698/2 "2018-09-02T11:28:36Z")

</div>

Yep. Use a [`date_histogram` aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html) on the timestamp field, with a monthly interval. Then add a [`sum` aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html) for each of the two fields.

---

<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:** [September 30, 2018, 11:28am UTC](https://discuss.elastic.co/t/sum-one-or-more-fields-with-date-aggregation/145698/3 "2018-09-30T11:28:40Z")

</div>

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