Hi.
I'm trying to get the top N documents for a specific aggregation , but with multiple term buckets - or any other way to get the results.
Basically , I have a documents with from.ip,from.hostname , to.ip,to.hostname, from.bytes,to.bytes, total.bytes (amongst other) fields.
I would like to just get the top 10 documents in terms of sum total.bytes.
In sql terms...
select from.ip,from.hostname,to.ip,to.hostname,sum(total.bytes) from myTable group by from.ip,from.hostname,to.ip,to.hostname
I have the following query request, but it returns the top 10 for Each bucket , which obviously results in waaay too many results.
P.s. I know my query is wrong in that it sorts on _count and not sum(total.bytes) ...
{
"query": {
"match_all": {}
},
"size": 10,
"aggs": {
"group": {
"terms": {
"field": "from.ip.raw",
"size": 10,
"order": {
"_count": "desc"
}
},
"aggs": {
"group": {
"terms": {
"field": "from.hostname.raw",
"size": 10,
"order": {
"_count": "desc"
}
},
"aggs": {
"group": {
"terms": {
"field": "to.ip.raw",
"size": 10,
"order": {
"_count": "desc"
}
},
"aggs": {
"group": {
"terms": {
"field": "to.hostname.raw",
"size": 10,
"order": {
"aggval": "desc"
}
},
"aggs": {
"aggval": {
"sum": {
"field": "total.bytes"
}
}
}
}
}
}
}
}
}
}
}
}