Thanks @mconlin for the hint. The query I got it working is the following:
{
"query": {
"filtered": {
"filter": {
"and" : [
{ "term": { "gender_id": 1 } },
{ "term": { "books.b_id": 2065} }
]
}
}
},
"facets": {
"book_cnt": {
"terms": {
"field": "books.b_id",
"size": 5
}
}
}
}
Turns out it's better to use the filter in the query itself instead of as a separate facet.