Sorting on Multiple Fields

前端 未结 5 1530
执笔经年
执笔经年 2021-01-04 19:31

Does Nest support sorting on multiple fields? For example, say I want to sort first by FieldA ascending and then by FieldB descending.

My current approach looks some

5条回答
  •  猫巷女王i
    2021-01-04 19:36

    for sorting on multiple dynamic fields, SortDescriptor can be useful.

            var sortDescriptor = new SortDescriptor<{YourType}>();
    
            sortDescriptor.Field(f => f.YourFieldName, Nest.SortOrder.Ascending);
    
            // If Field Name is Dynamic
            sortDescriptor.Field(
                "someOtherFieldName",
                Nest.SortOrder.Descending);         
    
            var searchResponse = await client.SearchAsync<{YourType}>(x => x
            .Query(y => query)
            .Sort(s => sortDescriptor)
            .From(from)
            .Size(size)
            );
    

提交回复
热议问题