Date histogram filter different math operations

Hi, how can I create a date histogram where I have this source datas:

   {
        "_index" : "test-data-2021-6-24",
        "_type" : "_doc",
        "_id" : "wB0PDnwBqyyjw7qp6Ih_",
        "_score" : 1.0,
        "_source" : {
          "id" : "51CnRcQfkm5syoUlQAWBUA_25",
          "value" : 9435.5
        }
      },
      {
        "_index" : "test-data-2021-6-24",
        "_type" : "_doc",
        "_id" : "RR0QDnwBqyyjw7qpB4nl",
        "_score" : 1.0,
        "_source" : {
          "id" : "MONbgqlIBvRUf1GU5fU0ag_15",
          "value" : 616.955
        }
      }

I have to multiply for example the field "value" data with "id" : "51CnRcQfkm5syoUlQAWBUA_25" *10 and i have to multiply the field "value" with "id" : "51CnRcQfkm5syoUlQAWBUA_25" *1000 and create the histogram. I have try with this query but it's not correct

GET test-data*/_search
{
  
  "track_total_hits": true,
  "size": 5000,
  "sort": [
    {
      "timestamp": {
        "order": "desc",
        "unmapped_type": "boolean"
      }
    }
  ],
  "version": true,
  "fields": [
    {
      "field": "*",
      "include_unmapped": "true"
    },
    {
      "field": "timestamp",
      "format": "strict_date_optional_time"
    }
  ],
  "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" 
      }
    }
  },
  "stored_fields": [
    "*"
  ],
  "_source": false,
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "range": {
            "timestamp": {
              "gte": "2020-08-11T00:00:00.000Z",
              "lte": "2022-11-11T23:59:59.000Z",
              "format": "strict_date_optional_time"
            }
          }
        
        },
        {
          "bool": {
            "should": [
              {
                "match_phrase": {
                  "id": "51CnRcQfkm5syoUlQAWBUA_10"
                }
              },
              {
                "match_phrase": {
                  "id": "51CnRcQfkm5syoUlQAWBUA_12"
                }
              }
            ],
            "minimum_should_match": 1
          }
        }
      ]
    }
  }
}

Can anyone help me? Thanks in advance

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