Group by consecutive values in elastic search

I have document structure like below :-1:
{
"id" : 1,
"imei" : "1002786191",
"date" : 2018-04-15",
"totalData" : [
{
"latitude" : 1.89754,
"longitude" : 2.89765,
"speed" : 0,
"gpsdt" : "2018-04-15T09:18:23"
},
{
"latitude" : 3.89754,
"longitude" : 2.89765,
"speed" : 0,
"gpsdt" : "2018-04-15T09:18:23"
}

                    ],

}

Now I have to find vehicle stopage time, like for how much time vehicle took a stopage.
So for this I need to perform a group by operation and I'll group lat and long and will apply a where clause for speed ..because if vehicle was stopped then speed must be 0.

But now let me explain my problem : If a vehicle is stopped for 1 hour at point A whose lat longs are (1.2345 and 5.7890) and then it starts moving and for 3 hours it continously moving and it comes back at same point A(1.2345,5.7890) and it is stopped for 2 hours because starting and ending point is same so lat long also would be same.
So to find stopage time for these two stopage , If I do group by lat and long then for both stopage the value of lat long fields would be same. But I have to consider them 2 stopage , not only one. because after first stopage vehicle has moved to some distance so I'll consider them two separate stopage.
So please suggest me a method/approach to write a query in elasticSearch.
I tried too much but did not find any solution.

Thanks in advance.
!wq

Since everything seem to be stored in a single document I would suggest doing this calculations in your application before you store the document in elasticsearch.

Is it not possible by using any method/approach?
Because I did not find any way to calculate stoppage time for a vehicle.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.