Hi,
I'm trying to get user session duration by day for the last 30 days from windows logs, so I used Transform but something wrong in my script, I always get duration for all period recorded: from the first login to the last logout.
I saw all similar subjet, but I didn't find somthing working for me.
PUT _transform/windows-login-durations
{
"source": {
"index": [
"windows-security-logs-*"
],
"query": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"match": {
"EventID": "4634"
}
}
],
"minimum_should_match": 1
}
},
{
"bool": {
"should": [
{
"match": {
"EventID": "4624"
}
}
],
"minimum_should_match": 1
}
}
],
"minimum_should_match": 1
}
}
},
"pivot": {
"group_by": {
"TargetLogonId": {
"terms": {
"field": "TargetLogonId"
}
},
"TargetUserName.keyword": {
"terms": {
"field": "TargetUserName.keyword"
}
},
"Hostname.keyword": {
"terms": {
"field": "Hostname.keyword"
}
},
"timestamp": {
"terms": {
"field": "@timestamp"
}
}
},
"aggregations": {
"time_frame.lte": {
"max": {
"field": "@timestamp"
}
},
"time_frame.gte": {
"min": {
"field": "@timestamp"
}
},
"duration": {
"bucket_script": {
"buckets_path": {
"min": "time_frame.gte.value",
"max": "time_frame.lte.value"
},
"script": "(params.max - params.min)/1000"
}
}
}
},
"frequency": "1m",
"dest": {
"index": "windows-login-durations"
}
}