# ElasticSearch Nest syntax for Script based sorting with SortDescriptor

**URL:** <https://discuss.elastic.co/t/elasticsearch-nest-syntax-for-script-based-sorting-with-sortdescriptor/300255>\
**Category:** Elasticsearch\
**Tags:** painless, language-clients\
**Created:** [March 21, 2022, 11:55pm UTC](https://discuss.elastic.co/t/elasticsearch-nest-syntax-for-script-based-sorting-with-sortdescriptor/300255 "2022-03-21T23:55:05Z")\
**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 21, 2022, 11:55pm UTC](https://discuss.elastic.co/t/elasticsearch-nest-syntax-for-script-based-sorting-with-sortdescriptor/300255/1 "2022-03-21T23:55:05Z")

</div>

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:

```auto
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"));

```

---

<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 18, 2022, 11:55pm UTC](https://discuss.elastic.co/t/elasticsearch-nest-syntax-for-script-based-sorting-with-sortdescriptor/300255/2 "2022-04-18T23:55:07Z")

</div>

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