# Nest Client alternative for AddSortField in 2.x

**URL:** <https://discuss.elastic.co/t/nest-client-alternative-for-addsortfield-in-2-x/46660>\
**Category:** Elasticsearch\
**Created:** [April 7, 2016, 10:26am UTC](https://discuss.elastic.co/t/nest-client-alternative-for-addsortfield-in-2-x/46660 "2016-04-07T10:26:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavang6](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pavang6](https://discuss.elastic.co/u/pavang6)\
**Post date:** [April 7, 2016, 10:26am UTC](https://discuss.elastic.co/t/nest-client-alternative-for-addsortfield-in-2-x/46660/1 "2016-04-07T10:26:15Z")

</div>

Currently, we use NEST client for all indexing operations where the "AddSortField" was used to sort the analyzed field (along with a sort analyzer). Looks like this option is not available anymore in 2.X. Are there any alternatives for this? Or any recommendations on sorting analyzed fields in 2.X would be much appreciated.

Note: Current NEST and Elasticsearch version being used is 1.X

Thanks,

Pavan

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [April 10, 2016, 9:22pm UTC](https://discuss.elastic.co/t/nest-client-alternative-for-addsortfield-in-2-x/46660/2 "2016-04-10T21:22:08Z")

</div>

`AddSortField` in NEST 1.x is just a convenience method for mapping a property as a [`multi_field`](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/_multi_fields.html) with a sort _sub-field_ to be used when sorting; for string fields where no SortAnalyzer is specified, this field is [`not_analyzed`](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/string.html#string).

To achieve the same in NEST 2.x, you can use [fluent mapping](https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/auto-map.html#auto-mapping-with-overrides) to map a property as a multi\_field, adding a sort sub-field

```auto
var descriptor = new CreateIndexDescriptor("myindex")
    .Mappings(ms => ms
        .Map<Company>(m => m
            .Properties(ps => ps
                .String(s => s
                    .Name(n => n.Name)
                    // map as multi_field
                    .Fields(fs => fs
                        .String(ss => ss
                            .Name("sort")
                            .Index("sortAnalyzer")
                        )
                    )
                )
            )
        )
    );

```

When sorting, you would then sort on `name.sort`

```auto
var response = client.Search<Company>(s => s
    .Query(q => q.MatchAll())
    .Sort(ss => ss
        .Ascending(p => p.Name.Suffix("sort"))
    )
);

```

---

<div class="post-metadata">

**Author:** ![pavang6](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pavang6](https://discuss.elastic.co/u/pavang6)\
**Post date:** [April 11, 2016, 7:08am UTC](https://discuss.elastic.co/t/nest-client-alternative-for-addsortfield-in-2-x/46660/3 "2016-04-11T07:08:13Z")

</div>

Thanks for the reply, Will make the changes suggested by you 🙂

---

<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:** [July 5, 2017, 11:00pm UTC](https://discuss.elastic.co/t/nest-client-alternative-for-addsortfield-in-2-x/46660/4 "2017-07-05T23:00:50Z")

</div>


