# Date histogram data precalculation

**URL:** https://discuss.elastic.co/t/date-histogram-data-precalculation/286574
**Category:** Elasticsearch
**Created:** [October 13, 2021, 6:32am UTC](https://discuss.elastic.co/t/date-histogram-data-precalculation/286574 "2021-10-13T06:32:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![scorona85](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@scorona85](https://discuss.elastic.co/u/scorona85)
#### Post date: [October 13, 2021, 6:32am UTC](https://discuss.elastic.co/t/date-histogram-data-precalculation/286574/1 "2021-10-13T06:32:34Z")

</div>

Hi,  
is there a way to perform operations on the data before creating the aggregation? In my example the aggregation is created and then the aggregate data is multiplied \* 10. I have to multiply the data and than aggregate (without change the original data). Thanks

```auto
  "aggs": {
    "dateHistogram": {
      "date_histogram": {
        "field": "timestamp",
        "time_zone": "Europe/Rome",
        "min_doc_count": 1,
        "calendar_interval": "1M"
      },
      "aggs": {
        "cumulativeSales": {
          "sum": {
            "field": "value"
          }
        }
      }
    }
  },
    "script_fields": {
    "formulaField": {
      "script": { 
        "source": "doc['value'].value * 10" 
      }
    }
  }

```

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [October 13, 2021, 6:58am UTC](https://discuss.elastic.co/t/date-histogram-data-precalculation/286574/2 "2021-10-13T06:58:24Z")

</div>

You might want to look at using [Map a runtime field | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/runtime-mapping-fields.html)

---

<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 10, 2021, 6:59am UTC](https://discuss.elastic.co/t/date-histogram-data-precalculation/286574/3 "2021-11-10T06:59:22Z")

</div>

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