{'aggs': {
'date_range': {
'date_histogram': {
'field': "End",
'calendar_interval': '1h',
'format': 'yyyy-MM-dd HH:mm:ss'
}, 'aggs': {
'sumed_value': {
'sum': {
'script': {
'source':
"return doc['value_sum'].value * (doc['End'].value - curent_interval) / 3600000;",
'lang': 'painless',
'params': {'curent_interval': 'date_range'
}
}
}
}
}
}
}
}
Hi, I want to use the date in date_histogram when calculating sum.
Explanation via example: My date_histogram brings me the Jobs in that range hourly. Let’s take the value of the example Job here as 100watts. For example: If a Job starts at 10.00 and ends at 11.30, the histogram value at 10.00 covers between 10.00 and 11.00 and for 10.00 I need to get the sum value of 100watts and I can already get this value. Secondly, the histogram value that comes in at 11.00 covers between 11.00 and 12.00, but my Job ends at 11.30. For this, I need to make proportioning in the Script. And if I know that the value of date_histogram in this script is 11.00, I can do this calculation. The “curent_interval” value I specified in the code should be this 11.00 date_histogram value. For this, I need this value in the sum script from the date_histogram.
I want to use the prorated data in sum.