Stats Aggregation Result with Custom Calculation on ES 5.0.1

Hey,

I've got a question regarding custom calculation on stats aggregation.
I'm using elastic search version 5.0.1 and trying to get a custom result of a stats aggregation which is based on calculation between specific document fields.

I've looked at scripted metric aggregation but since it's an experimental it's not an option -
'This functionality is experimental and may be changed or removed completely in a future release.'

I think a simple example should be the easiest way to understand the requirements:

DOCS:

Document #1:
Field: http_request_count, Value: 10;
Field: http_request_latency, Value: 10000;

Document #2:
Field: http_request_count, Value: 100;
Field: http_request_latency, Value: 2000;

STATS AGGREGATION:

"query": {
simple query with match filter and range..
},
"aggregations" : {
"MY_CUSTOM_AGG" : {
"stats" : {
"field" : "metrics.http_request_latency.value"
}
}
},

EXPECTED RESULT:

Expected latency calculation on both document values:
(1010000+1002000)/(10+100) = 2727.27

Expected result on 'http_request_latency' field:

"aggregations": {
"MY_METRIC_AGG": {
"count": 2,
"min": 2000,
"max": 10000,
"avg": 2727.27,
"sum": 300000 (1010000+1002000)
}
}

ACTUAL RESULT:

Actual latency calculation:
(10000+2000)/2 = 6000

Actual result on 'http_request_latency' field:

"aggregations": {
"MY_METRIC_AGG": {
"count": 2,
"min": 2000,
"max": 10000,
"avg": 6000,
"sum": 12000 (10000+2000)
}
}

Is there any way to add some kind of custom calculation to the stats metric to be used before result aggregation?
I'll be happy to hear about other ways possible to achieve the expected result, if any.

Thanks in advance,
ZNachshon

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