If I understand the problem correctly this is what I call the "disappearing checkboxes" problem.
When you have multiple filtering dimensions to contend with e.g. brand, size and colour my advice is to group user selections into separate bool clauses as follows:
The min_should_match clause should be one less than the number of dimensions (in this case size/colour/brand). This ensures matches that hit a dimension in the agg tree always satisfy all other category selections.
While this fixes the aggregation results it does mean that hits may contain docs that match only 2 out of 3 top-level filter clauses. The top results are likely to be the ones that tick all the boxes but you can see the problem. To fix that you'd need to add a post_filter for the hits that insists on all 3 out of 3 filter clauses matching.
This is a general pattern that should work regardless of how many filtering dimensions you have.
Now the second filter section you see: Amsterdam (165), but when you click it it actually is (28) because the it has to calculate in combination with the first selected filter.
Current situation: all terms show the amount of counts they are in posts/pages
Current situation: all terms should show the amount of counts they are in posts/pages, but should accumulate the total count with other active filters.
So what I'm trying to achieve is show the user the results which will be shown if the clickable filter will be activated.
You have multiple facets (for want of a better word). e.g. City, type etc
Selections within a facet e,g City are multi-choice and logically ORed.
Selections across facets are ANDed so in Lucene-speak (type:1 OR type:2) AND (city:A OR city:B)
If that is true then the recipe I provided is how to show correct counts for the choices inside each facet.
The counts for city A and city B will be regardless of any current selections in the city facet and respectful of matching all other selections in all other facets e.g. types 1 or 2. The converse is true for the type counts which will be irrespective of any type selections and respectful of all other facet choices e.g city A or B
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.