I would like to calculate pourcentile between a count of terms aggregator in Elasticsearch.
My Query :
{
"query" : {
"match_all" : {}
},
"size" : 0,
"aggs": {
"eventName" : {
"terms" : { "field" : "json.eventName" }
}
}
}
Result aggregator :
"aggregations": {
"eventName": {
"doc_count_error_upper_bound": 0,
"buckets": [
{
"key": "term1",
"doc_count": 30235
},
{
"key": "term2",
"doc_count": 30216
},
{
"key": "term3",
"doc_count": 22177
},
{
"key": "term4",
"doc_count": 17173
}
]
}
}
I want this metric exemple between "term1" and "term4" : 56%
I think
scripted_metric
could help.Take a look at my answer for a different this question.
In your case, you could count over the two terms and then return term4Cnt / term1Cnt. A rough estimate of what you'd need:
This assumes that you know your terms (event name) in advance. You can also filter on the relevant events.
Hopes this helps.