rewrote the ES search query building