I can think of several:
- Aggs solution -
terms
agg to group by session ID and sub aggs to gather related login/out events - Stream solution - use
scroll
api sorted on session ID - Active users index - create doc with session ID on login, delete on logout
- Entity-centric index to track active sessions, durations and more.
Solution 1 is not scalable with large numbers of users and is needlessly bogged-down with historical inactive sessions.
Solution 2 is scalable but slow and requires custom querying code
Solution 3 requires custom indexing code but is easy to query
Solution 4 requires custom scripts (examples available) but offers greater potential insights into sessions.