Here is the payload used to filter the data, holdings is a nested type and in the aggregation it includes non matched count.
{"size":0,"query":{"bool":{"filter":[{"bool":{"filter":[{"bool":{"should":[{"bool":{"filter":[{"terms":{"keyInformation.enterpriseHandle":["XXXXXXXXXXXX"],"boost":1}}],"adjust_pure_negative":true,"boost":1}}],"adjust_pure_negative":true,"boost":1}},{"bool":{"filter":[{"bool":{"filter":[{"nested":{"query":{"bool":{"filter":[{"wildcard":{"holdings.parentStyle":{"wildcard":" *Commodities* ","case_insensitive":true,"boost":1}}}],"adjust_pure_negative":true,"boost":1}},"path":"holdings","ignore_unmapped":false,"score_mode":"max","boost":1}}],"adjust_pure_negative":true,"boost":1}}],"adjust_pure_negative":true,"boost":1}}],"adjust_pure_negative":true,"boost":1}}],"adjust_pure_negative":true,"boost":1}},"_source":{"includes":["keyInformation.portfolioHandle"],"excludes":[]},"aggregations":{"parentStyle":{"nested":{"path":"holdings"},"aggregations":{"parentStyle":{"composite":{"size":600,"sources":[{"parentStyle":{"terms":{"field":"holdings.parentStyle","missing_bucket":false,"order":"asc"}}}]},"aggregations":{"count":{"reverse_nested":{},"aggregations":{"count":{"value_count":{"field":"keyInformation.portfolioHandle"}}}}}}}}}}
Output:
"aggregations" : {
"parentStyle" : {
"doc_count" : 204,
"parentStyle" : {
"after_key" : {
"parentStyle" : "U.S. Stocks"
},
"buckets" : [
{
"key" : {
"parentStyle" : "Cash"
},
"doc_count" : 16,
"count" : {
"doc_count" : 14,
"count" : {
"value" : 14
}
}
},
{
"key" : {
"parentStyle" : "Commodities"
},
"doc_count" : 23,
"count" : {
"doc_count" : 14,
"count" : {
"value" : 14
}
}
},
{
"key" : {
"parentStyle" : "U.S. Stocks"
},
"doc_count" : 81,
"count" : {
"doc_count" : 14,
"count" : {
"value" : 14
}
}
}
]
}
}
}
}
But I am looking to return count only for "parentStyle" : "Commodities", how can I achieve this?