ElasticSearch Source - Calculate time difference between timestamps

Hi,

I am currently using Elasticsearch as the data source and trying to find the time difference between timestamps group by a session id.

I successfully group the session id and obtain the first instance and the last instance within a log file. However, I was not able to obtain these values using the MAX, MIN function.

Therefore, I was not able to calculate the time difference between the first instance and the last instance since these calculation functions did not work.

How can I calculate the timestamp difference in Grafana or do I need to do any configuration in Elasticsearch in order to reach the objective? Thanks