How to add custom painless script data in table panel?

Hello,

This is my first time posting a question so apologies in advance if I missed to provided required information. The dashboard has bunch of panel and one of the panels is a table panel showing the current temperature data of the vehicle, which works great. Our data backing the dashboard is sourced from an elasticsearch index. The data has elements like vehicle plate number, current temp and location (latitude and longitude) of which we have mapped them as geo_point. The requirement is to show how far the vehicle is from a given lat and lon.

image

I have created the necessary variables and the plan was to use painless script option while querying elasticsearch.

This works fine when querying scriped fields directly against elasticsearch for ex.
{
  "script_fields" : {
    "distanceInKm" : {
      "script" : {
        "params" : {
            "lat" : -18.946596,
            "lon" : -48.156662
         },
        "inline": "doc['location'].arcDistance(params.lat,params.lon) * 0.001"
      }
    }
  },
  "_source": ["@timestamp","plate"]
} 

And the data received would be something like

{
   "plate" : "ABC-123",
   "fields" : {
   "distanceInKm" : [
       14.3936588192492
    ]
 } 

}

But I cannot find a way to do this using grafana.

  • Tried using bucket script but that does not help as the query is translated as aggs and doc variable is not available to elasticsearch in aggs

So looking for some advice from this group.

TIA
Prasanna