I am using Elasticsearch Nest client in .Net application and looking for a syntax to add Params and Language in script based sorting with Sort Descriptor.
Below is the code with SortDescriptor :
string shortestDistance =
"def hqDistance = 0;" +
"if(!doc[params.headquartersCoordinatesField].empty)" +
"{" +
"hqDistance = (doc[params.headquartersCoordinatesField].arcDistance(params.latitude, params.longitude) * 0.000621371);" +
"}" +
"return hqDistance" ;
var sortDesc = new SortDescriptor<Provider>();
sortDesc.Script(s => s
.Script(o => o.Source("shortestDistance"))
.Order(SortOrder.Ascending)
.Type("Number"));
Here are my Params and Language code that I need to convert :
Lang = "painless",
Params = new Dictionary<string, object>
{
{"headquartersCoordinatesField", Field<Provider>(f => f.Headquarters.Coordinates)},
{"latitude", _latitude},
{"longitude", _longitude}
}
Can anyone please response on how to add Params and Painless language in SortDescriptor Script ?
I would really appreciate the help!