move es query to lib