This content is archived. See latest version here


Search results are by default sorted by relevance, given that a search query exists. By using the OrderBy, ThenBy, OrderByDescending and ThenByDescending methods it is possible to instead sort by a specific field.


    .OrderBy(x => x.PublicationDate)
    .ThenBy(x => x.Author.Name)

Sorting is supported on numerical types such as int and double, DateTime and strings.

Null values and SortMissing

By default documents with null values in a field on which the search results are being sorted on will be sorted first when using the OrderBy and ThenBy methods and last when using the OrderByDescending and ThenByDescending methods. For all types except strings this can be changed by supplying a second parameter of the SortMissing enum type.

    .OrderBy(x => x.PublicationDate, SortMissing.Last)

Sorting by geographical distance

The OrderBy and OrderByDescending methods both have an overload for ordering by geographical distance for fields of type GeoLocation. For more information see the topic for Geo Search.

Last updated: Sep 26, 2013