here is my search response:
{
"took": 638,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2705428,
"max_score": 0,
"hits": []
},
"aggregations": {
"group_by_source": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "jiwei",
"doc_count": 2599928,
"group_by_logtype": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "clickNumber",
"doc_count": 2599894
},
{
"key": "advAckAllNumber",
"doc_count": 34
}
]
}
},
{
"key": "zhitou",
"doc_count": 105473,
"group_by_logtype": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "clickNumber",
"doc_count": 105471
},
{
"key": "advAckAllNumber",
"doc_count": 2
}
]
}
},
{
"key": "kejin",
"doc_count": 15,
"group_by_logtype": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "clickNumber",
"doc_count": 13
},
{
"key": "advAckAllNumber",
"doc_count": 2
}
]
}
},
{
"key": "mex",
"doc_count": 11,
"group_by_logtype": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "clickNumber",
"doc_count": 10
},
{
"key": "advAckAllNumber",
"doc_count": 1
}
]
}
},
{
"key": "applovin",
"doc_count": 1,
"group_by_logtype": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "clickNumber",
"doc_count": 1
}
]
}
}
]
}
}
}
And here is my watch rules, how could I get the value of rates that defined in conditions in the email?
{
"trigger": {
"schedule": {
"cron": "0 0 11 * * ?"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"logstash-*"
],
"types": [],
"body": {
"size": 0,
"query": {
"bool": {
"must": {
"range": {
"@timestamp": {
"gte": "now-8d/d",
"lte": "now-8d/d",
"time_zone": "+00:00"
}
}
},
"filter": {
"query_string": {
"query": "(appid:1179908959)AND(log_type:(clickNumber|advAckAllNumber))"
}
}
}
},
"aggs": {
"group_by_source": {
"terms": {
"field": "source.keyword",
"size": 50
},
"aggs": {
"group_by_logtype": {
"terms": {
"field": "log_type.keyword"
}
}
}
}
}
}
}
}
},
"condition": {
"script": {
"source": "def hg = 0.0005;def lw = 0.0001;def len_th = ctx.payload.aggregations.group_by_source.buckets.size();def rate = 0.0;def rates = new HashMap();def lt = 0;for (def i = 0; i < len_th; i++) { lt = ctx.payload.aggregations.group_by_source.buckets[i].group_by_logtype.buckets.length;if (lt === 1 ) { rate = 0 } else { rate = ctx.payload.aggregations.group_by_source.buckets[i].group_by_logtype.buckets.1.doc_count / ctx.payload.aggregations.group_by_source.buckets[i].group_by_logtype.buckets.0.doc_count } if ( rate < lw || rate > hg ) { rates[ctx.payload.aggregations.group_by_source.buckets[i].key] = rate } } return len_th === 5 ;",
"lang": "painless"
}
},
"actions": {
"email_admin": {
"email": {
"profile": "standard",
"from": "bo.zhang@jcmob.net",
"to": [
"bo.zhang@jcmob.net"
],
"subject": "J&C source activate rate is out of range",
"body": {
"text": " The info locate at: http://10.61.8.15:5601/goto/50f91b750a67fe933dd52e431b250d3f"
}
}
}
}
}