Guys, I already struggled from es docs for days,
but not a better solution could be found.
Need your professional opinions!!
I have these recorded data lines:
{"uid":1, "login": "2024-06-28 17:00:00", "logout":"2024-06-28 18:00:00"}
{"uid":1, "login": "2024-06-28 18:20:00", "logout":"2024-06-28 18:50:00"}
{"uid":2, "login": "2024-06-28 18:00:00", "logout":"2024-06-28 18:10:00"}
....
what I have to answer is, inside time range: 2024-06-28 17:30:00 ~~ 2024-06-28 18:30:00
,
how many users have stayed longer than 30 minutes.
it's hard to calculate the accurate seconds/minutes when time range
become a dynamic search parameter.
I do found that, I could calc a real-online-duration
in specified time range with "script_fields" feature, but that is a secment data, which should be sum ed togather then filtered out.
{
"size": 3,
"_source": true,
"script_fields": {
"my_duration_sec": {
"script": {
"source": """
long li = doc['LoginTime'].value;
long lo = doc['LogoutTime'].value;
if (li < params['begin']) {
li = params['begin'];
}
if (lo == 0 || lo > params['end']) {
lo = params['end'];
}
return (lo - li);
""",
"params": {
"begin": 1719482400,
"end": 1719483000
}
}
}
}
How could I achieve this?
Thanks a lot.