Skip to content

Instantly share code, notes, and snippets.

@frcake
Last active November 30, 2018 13:41
Show Gist options
  • Save frcake/85a56ba77d88ceaa9a40756f95de54d6 to your computer and use it in GitHub Desktop.
Save frcake/85a56ba77d88ceaa9a40756f95de54d6 to your computer and use it in GitHub Desktop.
{
"aggs": {
"filter_incoming_calls": {
"filter": {
"bool": {
"must": [
{
"terms": {
"incoming_denver_customer_id": [
15938
]
}
}
]
}
},
"aggs": {
"countries": {
"terms": {
"field": "origin_country_name",
"size": 1000
},
"aggs": {
"total_calls_ner": {
"sum": {
"script": "int total = 0; total += doc['isaner'].value"
}
},
"total_calls_answered": {
"sum": {
"script": "int total = 0; if (doc['real_duration'].value != 0 ) {total += 1 }"
}
},
"total_minutes": {
"sum": {
"script": "double totalMinutes = 0; totalMinutes += doc['real_duration'].value; Math.round(totalMinutes * 100) / 100.0"
}
},
"total_calls": {
"bucket_script": {
"buckets_path": {
"doc_count": "_count"
},
"script": "params.doc_count"
}
},
"asr": {
"bucket_script": {
"buckets_path": {
"callsAnswered": "total_calls_answered",
"totalCalls": "total_calls"
},
"script": "double result = params.callsAnswered / params.totalCalls * 100; result = (double) Math.round(result * 100) / 100"
}
},
"ner": {
"bucket_script": {
"buckets_path": {
"callsNer": "total_calls_ner",
"totalCalls": "total_calls"
},
"script": "double result = (params.callsNer / params.totalCalls) * 100; result = (double) Math.round(result * 100) / 100;"
}
},
"aloc": {
"bucket_script": {
"buckets_path": {
"totalMinutes": "total_minutes",
"callsAnswered": "total_calls_answered"
},
"script": "double result = (params.totalMinutes / params.callsAnswered).doubleValue(); (double) Math.round(result * 100) / 100"
}
},
"sorting": {
"bucket_sort": {
"from": 0,
"size": 10
}
}
}
}
}
}
},
"size": 0
}
=> nil
{
"filter_incoming_calls": {
"doc_count": 2003400,
"countries": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [{
"key": "Algeria",
"doc_count": 1919796,
"asr": {
"value": 38.66
},
"ner": {
"value": 96.44
},
"aloc": {
"value": 131.16
}
},
{
"key": "Niger",
"doc_count": 27812,
"asr": {
"value": 0.73
},
"ner": {
"value": 33.92
},
"aloc": {
"value": 117.54
}
},
{
"key": "Tunisia",
"doc_count": 22560,
"asr": {
"value": 21.08
},
"ner": {
"value": 72.32
},
"aloc": {
"value": 68.33
}
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment