Search code examples
c#.netasp.net-web-apinestnest2

porting my code to NEST 2.0 and ElasticSearch 2.0


I'm doing a port of my .NET C# WebAPI from NEST 1.0 to the newest NEST 2.0. Elasticsearch has been updated to 2.0 as well.

.Filters() has been replaced with .Query() which is fine.

However, I can't find the equivalent for .SortAscending(). There is a .Sort() but how can I specify the order? (ascending, descending)

Intellisense shows I should pass a selector of type IPromise which is useful is some way but a plain example would be much better. Anyway, really can't understand by intellisense alone...


Solution

  • Here is the example.

    For asc:

    var searchResults = client.Search<Document>(s => s
        .Query(q => q.MatchAll())
        .Sort(sort => sort.Ascending(f => f.Name)));
    

    For desc:

    var searchResults = client.Search<Document>(s => s
        .Query(q => q.MatchAll())
        .Sort(sort => sort.Descending(f => f.Name)));
    

    Hope it helps.