Getting hit count before post-filter


I'm applying a post-filter (in order to get aggregations only on the original query scope). There is however a need to find/display the hit count before this post-filter was applied (otherwise we have to cache hits/hits/total which is not entirely portable for what we do)

I can obviously do something silly like

ValueCountBuilder agg = AggregationBuilders.count("hitsPrePostFilter").field("_uid");
request = request.addAggregation(agg);

but that's not ideal as it incurs unnecessary processing.

So I was wondering if there's a mechanism to get, in the same request, the hit count for the core/original query scope, before the post-filter was applied.

Thank you

Judging by the lack of activity on this one, it seems that a "fake aggregation" is the way to go here. Has anyone else encountered this use case?

A fake aggregation would work indeed, but I would recommend running a filter aggregation on a match_all query rather than a value_count aggregation.

Good point, thank you!