Hey ES community!
I have a query: (the part of code is below...btw script was taken from visualization in kibana request)
"aggs": {
"uuid": {
"terms": {
"field": "device_uuid",
"size": 5000,
"order": {
"_term": "desc"
},
"min_doc_count": "10"
},
"aggs": {
"geo": {
"cardinality": {
"field": "location"
}
},
"acc": {
"cardinality": {
"field": "accuracy"
}
},
"age": {
"cardinality": {
"script": {
"inline": "(doc['@timestamp'].date.getMillis() - doc['user_creation_time'].date.getMillis())/1000/60/60/24",
"lang": "painless"
}
}
}
}
}
},
"stored_fields": [
"*"
],
"script_fields": {
"user_age": {
"script": {
"inline": "(doc['@timestamp'].date.getMillis() - doc['user_creation_time'].date.getMillis())/1000/60/60/24",
"lang": "painless"
}
}
},
"docvalue_fields": [
"@timestamp",
"time",
"user_creation_time"
],
"query": {
"bool": {
"must": [
{
"match_all": {}
},
{
"match_phrase": {
"gc": {
"query": 1
}
}
},
{
"match_phrase": {
"solution": {
"query": "first"
}
}
},
I want to create an alert: when I have geo = 1 and acc = 1 and age >=2_ notify me via slack.
But i cannot understand how to check stats in all output buckets. The output of watcher is (only part of output):
"aggregations": {
"uuid": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 411288,
"buckets": [
{
"acc": {
"value": 37
},
"geo": {
"value": 42
},
"doc_count": 42,
"key": "234134",
"age": {
"value": 8
}
},
{
"acc": {
"value": 22
},
"geo": {
"value": 22
},
"doc_count": 25,
"key": "12342456",
"age": {
"value": 6
}
}
.......
I only know how to check in first bucket:
ctx.payload.aggregations.uuid.buckets.0.acc.value
I want to put condition something like:
"if (ctx.payload.hits.total == 0) return false; def nb=(ctx.payload.aggregations.uuid.buckets.0.age.value); def nu = (ctx.payload.aggregations.uuid.buckets.0.acc.value); def ng=(ctx.payload.aggregations.uuid.buckets.0.geo.value); if (nb>=2 && nu==1 && ng==1) return true; ---btw it doesnt work even for first bucket (