ok, found problem field name is timestamp not @timestamp, but now i get just 2 buckets for the full query where percent_used difference is > 1. I have 5000 servers reporting storage usage and 1 million documents and i dont think just 2 servers have increases 1% in last 90 days.
this is sample document:
{
"_index": "ueb-metrics-2017.04",
"_type": "object",
"_id": "e5304b10-6155-4086-bc0f-96e7a4d57569_capacity_2017.04.25_10.00",
"_score": null,
"_source": {
"type": "capacity",
"asset_tag": "e5304b10-6155-4086-bc0f-96e7a4d57569",
"timestamp": "2017-04-25T10:00:14.029811-06:00",
"capacity": {
"ir_used": 2,
"used": 0,
"available": 6000,
"percent_used": 0
}
},
"fields": {
"timestamp": [
1493136014029
]
},
"highlight": {
"type.keyword": [
"@kibana-highlighted-field@capacity@/kibana-highlighted-field@"
],
"type": [
"@kibana-highlighted-field@capacity@/kibana-highlighted-field@"
]
},
"sort": [
1493136014029
]
}
this i full query:
GET /ueb-metrics-*/_search
{
"size": 0,
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "type:capacity",
"analyze_wildcard": true
}
},
{
"range": {
"timestamp": {
"gte": "now-90d",
"lte": "now",
"format": "epoch_millis"
}
}
}
],
"must_not": []
}
},
"_source": {
"excludes": []
},
"aggs": {
"hosts": {
"terms": {
"field": "asset_tag.keyword",
"order": {
"_term": "desc"
}
},
"aggs": {
"dates": {
"date_histogram": {
"field": "timestamp",
"interval": "90d",
"time_zone": "Europe/Berlin"
},
"aggs": {
"percent-used-difference": {
"serial_diff": {
"buckets_path": "percent-used"
}
},
"percent-used": {
"max": {
"field": "capacity.percent_used"
}
},
"bucket-filter": {
"bucket_selector": {
"buckets_path": {
"percent_used_difference": "percent-used-difference"
},
"script": "(params?.percent_used_difference ?: 0) > 1"
}
}
}
},
"bucket-filter": {
"bucket_selector": {
"buckets_path": {
"date_count": "dates._bucket_count"
},
"script": "params.date_count > 0"
}
}
}
}
}
}
and result:
{
"took": 51,
"timed_out": false,
"_shards": {
"total": 25,
"successful": 25,
"failed": 0
},
"hits": {
"total": 1130449,
"max_score": 0,
"hits": []
},
"aggregations": {
"hosts": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 1129222,
"buckets": [
{
"key": "ff764213-0292-46c7-8ff3-63b52baf4c67",
"doc_count": 45,
"dates": {
"buckets": [
{
"key_as_string": "2017-04-24T00:00:00.000+02:00",
"key": 1492984800000,
"doc_count": 11,
"percent-used": {
"value": 79.71998596191406
},
"percent-used-difference": {
"value": 8.467666625976562
}
}
]
}
},
{
"key": "ff748769-855a-4f6e-9a93-f627d1d66a61",
"doc_count": 431,
"dates": {
"buckets": [
{
"key_as_string": "2017-04-24T00:00:00.000+02:00",
"key": 1492984800000,
"doc_count": 10,
"percent-used": {
"value": 101.27615356445312
},
"percent-used-difference": {
"value": 37.369319915771484
}
}
]
}
}
]
}
}
}