We'd need to then transform the results slightly to delete the unique_docs and replace the doc_count. I've not yet found a way to make this the default (i.e. aggregated nested but return the 'reverse' counts by default) which would be better since it avoids meddling with the e-s format overmuch.
The solution to this is a 'reverse nested' aggregation: https:/ /www.elastic. co/guide/ en/elasticsearc h/guide/ current/ nested- aggregation. html. For instance, in the example above (I have two servers with the current code, I get two networks.name buckets even though it's just one document:
{ OS-EXT- IPS:type" ,
"doc_ count": 4
"type": "string",
"name": "networks.
"options": [
{
"key": "fixed",
}
]
}
Adding a reverse_nested aggregation (notice the extra _unique_docs) :
{ OS-EXT- IPS:type" ,
"options" : [
" doc_count" : 4,
" key": "fixed",
" networks_ _OS-EXT- IPS:type_ unique_ docs": {
"doc_ count": 2
}
"name": "networks.
{
}
],
"type": "string"
},
We'd need to then transform the results slightly to delete the unique_docs and replace the doc_count. I've not yet found a way to make this the default (i.e. aggregated nested but return the 'reverse' counts by default) which would be better since it avoids meddling with the e-s format overmuch.