Use Filtered queries more efficiently for elasticsearch

This patch implements cleaner logic to build a query for elasticsearch and switches to terms filter for model filtering which should speed things up.