ElasticSearch Nest syntax for Script based sorting with SortDescriptor

I am using Elasticsearch Nest client in .Net application and looking for a syntax to use script based sorting with Sort Descriptor.

So what would be the sorting syntax to add Params and painless Language with SortDescriptor code as below:

string distance =
                "if(!doc[params.headquartersCoordinatesField].empty)" +
                "{" +
                "def 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(distance))
            .Order(SortOrder.Ascending)
            .Type("Number"));

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