# Nest .Sort() doesnt seem to except a list? Any work arounds?

**URL:** <https://discuss.elastic.co/t/nest-sort-doesnt-seem-to-except-a-list-any-work-arounds/264603>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [February 17, 2021, 5:52pm UTC](https://discuss.elastic.co/t/nest-sort-doesnt-seem-to-except-a-list-any-work-arounds/264603 "2021-02-17T17:52:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Whittaker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_whittaker/32/75325_2.png) [@Adam\_Whittaker](https://discuss.elastic.co/u/Adam_Whittaker)\
**Post date:** [February 17, 2021, 5:52pm UTC](https://discuss.elastic.co/t/nest-sort-doesnt-seem-to-except-a-list-any-work-arounds/264603/1 "2021-02-17T17:52:30Z")

</div>

Hello,

I am using ElasticSearch Nest Fluent DSL and cant seem to figure out how to create a list of Sorts that the .Sort() accepts.

I have an array of sorts and i want to convert them to work with Nest a bit like you can do with Filters:

new List\<Func\<QueryContainerDescriptor, QueryContainer\>\>();

Any ideas?

Thanks

---

<div class="post-metadata">

**Author:** ![Adam\_Whittaker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_whittaker/32/75325_2.png) [@Adam\_Whittaker](https://discuss.elastic.co/u/Adam_Whittaker)\
**Post date:** [February 19, 2021, 4:15pm UTC](https://discuss.elastic.co/t/nest-sort-doesnt-seem-to-except-a-list-any-work-arounds/264603/2 "2021-02-19T16:15:46Z")

</div>

Figured it out:

```auto
 Func<SortDescriptor<dynamic>, IPromise<IList<ISort>>> sortList = st =>
            {
                if (queryBuilder.Sort != null)
                {
                    foreach (var option in queryBuilder.Sort)
                    {    
                        if (option.SortOrder == "ASC")
                        {
                            st.Ascending(option.Key);
                        }
                        else
                        {
                            st.Descending(option.Key);
                        }
                    }
                }
                else
                {
                    st.Ascending(SortSpecialField.Score);
                }
                return st;
            };

```

Then in the query:

```auto
.Sort(sortList)

```

---

<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:** [March 19, 2021, 4:16pm UTC](https://discuss.elastic.co/t/nest-sort-doesnt-seem-to-except-a-list-any-work-arounds/264603/3 "2021-03-19T16:16:24Z")

</div>

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