converted code from elastcal to elasticsearch client