I managed to create the rate (success, failure, aborted) with runtime_mappings. Please share with me if there is a more optimized approach.
Query
GET discuss/_search
{
"size": 0,
"runtime_mappings": {
"status_success": {
"type": "long",
"script": {
"source": "if (doc['status'].value == 'SUCCESS') {emit(1)} else {emit(0)}"
}
},
"status_failure": {
"type": "long",
"script": {
"source": "if (doc['status'].value == 'FAILURE' || doc['status'].value == 'UNSTABLE') {emit(1)} else {emit(0)}"
}
},
"status_aborted": {
"type": "long",
"script": {
"source": "if (doc['status'].value == 'ABORTED') {emit(1)} else {emit(0)}"
}
}
},
"aggs": {
"by_workflow": {
"terms": {
"field": "workflow"
},
"aggs": {
"top_status": {
"top_metrics": {
"metrics": [
{"field": "status_success"},
{"field": "status_failure"},
{"field": "status_aborted"}
],
"sort": {
"id": "desc"
}
}
}
}
},
"success_rate": {
"avg_bucket": {
"buckets_path": "by_workflow>top_status[status_success]",
"gap_policy": "skip",
"format": "#%"
}
},
"failure_rate": {
"avg_bucket": {
"buckets_path": "by_workflow>top_status[status_failure]",
"gap_policy": "skip",
"format": "#%"
}
}
"aborted_rate": {
"avg_bucket": {
"buckets_path": "by_workflow>top_status[status_aborted]",
"gap_policy": "skip",
"format": "#%"
}
}
}
Results
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 421,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"by_workflow" : {
"doc_count_error_upper_bound" : 2,
"sum_other_doc_count" : 179,
"buckets" : [
{
"key" : "A",
"doc_count" : 102,
"top_status" : {
"top" : [
{
"sort" : [
23
],
"metrics" : {
"status_success" : 0,
"status_failure" : 1,
"status_aborted" : 0
}
}
]
}
},
{
"key" : "B",
"doc_count" : 78,
"top_status" : {
"top" : [
{
"sort" : [
47
],
"metrics" : {
"status_success" : 1,
"status_failure" : 0,
"status_aborted" : 0
}
}
]
}
},
{
"key" : "C",
"doc_count" : 62,
"top_status" : {
"top" : [
{
"sort" : [
57
],
"metrics" : {
"status_success" : 1,
"status_failure" : 0,
"status_aborted" : 0
}
}
]
}
}
]
},
"success_rate" : {
"value" : 0.6666666666666666,
"value_as_string" : "67%"
},
"failure_rate" : {
"value" : 0.3333333333333333,
"value_as_string" : "33%"
},
"aborted_rate" : {
"value" : 0.0,
"value_as_string" : "0%"
}
}
}
I'd like to create a pie chart (vega/vega-lite) using the success_rate
, failure_rate
, and aborted_rate
. Appreciate it if you can share any insights how to transform the rate into accessible array of data.