Sub-aggregate on a scripted bucket query?


(Casie Owen) #1

Hi,

The query below returns a percentage value at a daily grain. What I'm wondering is, can we do a sub aggregation on that to get, say, the min value of all the daily values for a month within this same query/without writing the values to a new index?

GET clientavailability_*/_search
{
"size": 1,
"aggs": {
"@timestamp": {
"date_histogram": {
"field": "@timestamp",
"interval": "1d"
},
"aggs": {
"filterSuccess": {
"filter": {
"match_all": {}
},
"aggs": {
"successCount": {
"sum": {
"field": "totalSuccessfulRequests"
}
}
}
},
"filterTotal": {
"filter": {
"match_all": {}
},
"aggs": {
"totalCount": {
"sum": {
"field": "totalRequests"
}
}
}
},
"scriptedBucket": {
"bucket_script": {
"buckets_path": {
"successCount": "filterSuccess>successCount",
"totalCount": "filterTotal>totalCount"
},
"script": {
"inline": "(params.successCount / params.totalCount) * 100"
}
}
}
}
}
},
"query": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "2017-07-01T00:00:00Z",
"lte": "2017-10-31T00:00:00Z"
}
}
},
{
"term": {
"experiences.microExperiences.experience": {
"value": "Launch Game or App|Launch Game or App"
}
}
}
]
}
}
}
Thanks,
Casie


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.