I have a field containing simple tags for example. I'd like to be able to use those tags to perform a faceted search but have the tag counters showing the counts of matches before the tag is used as a filter.
e.g.
Foo (20)
*Bar (25)* <--- selected tag
Bof (23) <--- if I select this tag 'Bar' is deselected and I get 23 results (which may or may not have documents tagged `Bar`
Bif (19)
At the moment I have a search that looks like this:
{
"query":{
"bool":{
"filter":[
{
"term":{
"tag":"Bar"
}
}
]
}
},
"aggs":{
"by_tag":{
"terms":{
"field":"tag",
"size":0
}
}
}
}
This will give me counts for all document tags where the document is tagged Bar already
I could perform multiple searches to get the aggregations, but wondered if there was a simpler way?