Date histogram data precalculation

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

  "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" 
      }
    }
  }

You might want to look at using Map a runtime field | Elasticsearch Guide [7.15] | Elastic

1 Like

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