LPS-48695 Fix ES performance with categories

Hi Dante,

Can you please evaluate if this pull solves the peformance regression caused by LPS-48695? Note, I'm playing with the possibilities right now, so even if it works, it's not in its final form. And if it fails...

Let me know your results.

Thanks,
Tibor

/cc @ealonso