As part of our development , we have to apply some business rules like whether user has viewing rights to the search string or not.
The elastic query we form applies the query criteria given by the user and search elasticsearch and gets search results and aggregations on it. Now , if we apply the filter conditions after elastic results are fetched , then we will have to compute the aggregations against based on the results which don't make the cut. The filter criteria is given by a service and may not entirely present in the dataset.
How can i work around this problem besides computing aggregations based on records eliminated.