I would like to construct a query that would calculate a moving average. The working query is below. I need to do an initial query for the specific function to be analyzed. After that I am doing a four week from present sample in 15 minute intervals. The return condition is true/false and I need a percentage of false returns. I need the scripted percentage (total_fails.doc_count / time_slices.doc_count) in the time_slices buckets. I think I need a bucket_script but I can't seem to get it in the right place. I either get a "No aggregation found for path.... or a Only sibling pipeline aggregations are allowed at the top level error.
"percent_fails": {
"bucket_script": {
"buckets_path": {"fail_count": "total_fails.doc_count", "total_count": "doc_count"},
"script": "fail_count / pass_count * 100"
}
}
GET sasha-*/_search
{
"size": 0,
"query": {
"bool": {
"must_not": [{
"match_phrase": {
"returned_xml": "AssetSearch: Missing attuid"
}
},
{
"match_phrase": {
"returned_xml": "not found in GPS, IPDB or NC3"
}
},
{
"match_phrase": {
"returned_xml": "enterprise_customer_asset_list failed"
}
},
{
"match_phrase": {
"returned_xml": "Missing AssetID, ticketNumber, circuit_id"
}
},
{
"match_phrase": {
"returned_xml": "is not a telephone number"
}
},
{
"match_phrase": {
"returned_xml": "Missing platform_object_key"
}
},
{
"match_phrase": {
"returned_xml": "Can't find any info on MAC address"
}
}],
"must": [{
"term": {
"functional_name.keyword": {
"value": "getAssetInformation"
}
}
},
{
"range": {
"@timestamp": {
"gte": "now-4w",
"lte": "now"
}
}
}]
}
},
"aggs": {
"time_slices": {
"date_histogram": {
"field": "@timestamp",
"interval": "15m"
},
"aggs": {
"total_fails": {
"filter": {
"term": {
"return_condition": "true"
}
}
}
}
}
}
}
{
"took": 88,
"timed_out": false,
"_shards": {
"total": 215,
"successful": 215,
"failed": 0
},
"hits": {
"total": 106506,
"max_score": 0,
"hits": []
},
"aggregations": {
"time_slices": {
"buckets": [
{
"key_as_string": "2018-08-15T17:15:00.000Z",
"key": 1534353300000,
"doc_count": 21,
"total_fails": {
"doc_count": 0
}
},
{
"key_as_string": "2018-08-15T17:30:00.000Z",
"key": 1534354200000,
"doc_count": 104,
"total_fails": {
"doc_count": 0
}
},