Refactor and start implementation of ES based events query