Im running this script to calculate the distances between geo points based on groovy script.
{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "xxxxxx",
"analyze_wildcard": true
}
},
"filter": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "2012-03-01 00:00:00.000",
"lte": "2012-03-31 23:59:59.999",
"format": "yyyy-MM-dd HH:mm:ss.SSS"
}
}
}
],
"must_not": []
}
}
}
},
"aggs": {
"by_day": {
"date_histogram": {
"field": "@timestamp",
"interval": "day"
},
"aggs": {
"gpoints": {
"scripted_metric": {
"init_script": "_agg['points'] = [];",
"map_script": " _agg['points'] = doc['geoip.location'];",
"reduce_script": "diff = 0;prev_p = 0;count = 0;for(p in _aggs){if(count == 0){prev_p = p.points; count = 1;} else{diff=prev_p[0].distanceInKm(p.points[0].getLat(),p.points[0].getLon()); prev_p = p.points;};}; return diff;"
}
}
}
}
}
}
but i got the following error:
{
"error": {
"root_cause": [],
"type": "reduce_search_phase_exception",
"reason": "[reduce] ",
"phase": "fetch",
"grouped": true,
"failed_shards": [],
"caused_by": {
"type": "script_exception",
"reason": "failed to run inline script [diff = 0;prev_p = 0;count = 0;for(p in _aggs){if(count == 0){prev_p = p.points; count = 1;} else{diff=prev_p[0].distanceInKm(p.points[0].getLat(),p.points[0].getLon()); prev_p = p.points;};}; return diff;] using lang [groovy]",
"caused_by": {
"type": "missing_method_exception",
"reason": "No signature of method: org.elasticsearch.common.geo.GeoPoint.distanceInKm() is applicable for argument types: (java.lang.Double, java.lang.Double) values: [28.233599960803986, -82.18120012432337]"
}
}
},
"status": 503
}
is there away to fix this code? Or, can anyone suggest away to find the difference between geo points and detect if someone was moving or not during a day?. Also, I want to know how far he was moving?