I have an elastic index which has documents for user state history. Data looks like this;
{
"session_id": "yunus",
"state_name": "start",
"entry_time": "2016-11-09 15:27:03"
},
{
"session_id": "yunus",
"state_name": "end",
"entry_time": "2016-11-09 16:30:00"
},
{
"session_id": "can",
"state_name": "start",
"entry_time": "2016-11-09 12:01:00"
},
{
"session_id": "rick",
"state_name": "start",
"entry_time": "2016-11-09 09:00:00"
},
{
"session_id": "rick",
"state_name": "end",
"entry_time": "2016-11-10 10:00:00"
}
I want to aggregate by state name with date histogram but for only relevant last state at that time. So result can be;
2016-11-08
start = 0
end = 0
2016-11-09
start = 2
end = 1
2016-11-10
start = 1
end = 2
Actually plan is to generate grouped bar chart with timeline to show states change over time.
I tried several things like aggregation pipelines, top hits but couldn't make any progress.
Any help appreciated.