How to find the time difference between two documents (rows in sql) in an index (table in sql) with same Id

You can't really do that in a NoSQL world. It's better to do that kind of join at index time.

So wait for the end of an event and compute that at index time.

There's for example this logstash plugin which can help. In case you're using logstash.