# How to add Script Params and Language using SortDescriptor in ElasticSearch Nest client

**URL:** <https://discuss.elastic.co/t/how-to-add-script-params-and-language-using-sortdescriptor-in-elasticsearch-nest-client/300498>\
**Category:** Elasticsearch\
**Tags:** painless, language-clients\
**Created:** [March 23, 2022, 7:51pm UTC](https://discuss.elastic.co/t/how-to-add-script-params-and-language-using-sortdescriptor-in-elasticsearch-nest-client/300498 "2022-03-23T19:51:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aashini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aashini/32/98857_2.png) [@aashini](https://discuss.elastic.co/u/aashini)\
**Post date:** [March 23, 2022, 7:51pm UTC](https://discuss.elastic.co/t/how-to-add-script-params-and-language-using-sortdescriptor-in-elasticsearch-nest-client/300498/1 "2022-03-23T19:51:13Z")

</div>

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 :

```auto
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 :

```auto
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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 20, 2022, 7:51pm UTC](https://discuss.elastic.co/t/how-to-add-script-params-and-language-using-sortdescriptor-in-elasticsearch-nest-client/300498/2 "2022-04-20T19:51:15Z")

</div>

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