1 aggregate bucket with multiple filters

I have a nested collection under the root documents, where I am trying to get a single aggregate value_count based on multiple aggregate filters.
For Example: I need count of address ids where city is LA or San Diego and State is CA

The Filter Aggregation allows me to put only 1 filter condition, and does not like an array of filters,
Then i looked at the filters, which allows me to add multiple filters, but gives a bucket for associated filter.

Blockquote
"_f113-c0-test_aggregate": {
"nested": {
"path": "test_addresses"
},
"aggs": {
"_f113-c0-test_aggregate": {
"filters": {
"filters": [
{
"terms": { "test_addresses.state": [ "CA" ] }
},
{
"terms": {
"test_addresses.city": [ "Los Angeles" , "San Diege" ]
}
}
]
},
"aggs": {
"_f113-c0-test_aggregate": {
"value_count": {
"field": "test_addresses.AddressId"
}
}
}
}
}
}

Blockquote

How can i get 1 aggregate count with multiple filters applied to it.

Thanks

You can use a bool query and multiple terms queries inside the bool's must section. Then throw that whole thing inside the filter aggregation :slight_smile:

1 Like

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