Nest Client alternative for AddSortField in 2.x

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

AddSortField in NEST 1.x is just a convenience method for mapping a property as a multi_field with a sort sub-field to be used when sorting; for string fields where no SortAnalyzer is specified, this field is not_analyzed.

To achieve the same in NEST 2.x, you can use fluent mapping to map a property as a multi_field, adding a sort sub-field

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

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

Thanks for the reply, Will make the changes suggested by you :slight_smile: