Ref this thread: Content.query aggregations by query (not field)
A filter aggregation could work like this:
{
"aggs" : {
"red_products" : {
"filter" : { "term": { "color": "red" } },
"aggs" : {
"avg_price" : { "avg" : { "field" : "price" } }
}
}
}
}