Hello Team,
I am using ES to check chatbot's response success rate. (document contains message and tag)
I want to visualize that
- total count : the number of documents that contain
@send
incustomTags
keyword field - failed count : the number of documents that contain
@fail
incustomTags
keyword field - success count : (total count - failed count)
So I composed a query like below :
{
"query": {
"bool": {
"filter": [
{
"match": {
"sender": 10000
}
}
]
}
},
"aggs": {
"report": {
"date_histogram": {
"field": "@timestamp",
"interval": "60m"
},
"aggs": {
"send": {
"filter": {
"match": {"customTags": "@send"}
},
"aggs": {
"count": {
"sum": {
"field": "sender"
}
}
}
},
"fail": {
"filter": {
"match": {"customTags": "@fail"}
},
"aggs": {
"count": {
"sum": {
"field": "sender"
}
}
}
},
"success": {
"bucket_script": {
"buckets_path": {
"total": "send > count",
"fail": "fail > count"
},
"script": "(params.total - params.fail)/10000"
}
}
}
}
}
}
As you can see, "send" and "fail" aggregations contain "sum aggregation" for calculation.
So my questions are
- Is it fine to use query like that to calculate with results?
- Could I setup this query using
visualization UI
? I tried many times but didn't find good one.
For the reference I attach the response of query below.
{
"took": 22,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 125105,
"max_score": 0,
"hits": []
},
"aggregations": {
"whole_result": {
"buckets": [
{
"key_as_string": "2018-06-26T15:00:00.000Z",
"key": 1530025200000,
"doc_count": 4294,
"fail": {
"doc_count": 86,
"count": {
"value": 8600
}
},
"send": {
"doc_count": 173,
"count": {
"value": 17300
}
},
"success": {
"value": 87
}
},
...
Thanks for help in advance!