c#-通过在Nest Elastic Search中降序获得不同的术语
作者:互联网
我正在尝试使用Nest Elastic Search按CarsSold降序获得前10名不同的汽车订单.
我的弹性课看起来像:
public class Make
{
public string MakeId {get;set;}
public string MakeName {get;set;}
public string Address { get;set;}
public List<Cars> Models {get;set;}
}
public class Cars
{
public int Id{get;set;}
public string CarsName {get;set;}
public int CarsSold {get;set;}
}
我尝试使用下面的代码,但该值未按CarsSold Descending排序:
var cars = Client.Search<Make>(s => s
.Size(0)
.Aggregations(a => a
.Terms("unique", t => t
.Field(f => f.Models.FirstOrDefault().CarsName)
.Size(10)
.Aggregations(a2 => a2
.Max("authStats", s1 => s1.Field(f => f.Models.FirstOrDefault().CarsSold))
)
)
)
);
任何帮助将不胜感激.
好吧,我尝试同时使用汇总的Max And Stats.
解决方法:
无论如何都找到了方法.
它可能会帮助像我这样挣扎的其他人:
使用以下代码完成:
var result = Client.Search<Make>(s => s
.Aggregations(a => a
.Terms("unique", te => te
.Field("cars.carsName")
.Size(10)
.OrderDescending("totalCount")
.Aggregations(aa => aa
.Max("totalCount", ma => ma
.Field("cars.carsSold")
)
)
)
)
);
标签:nest,elasticsearch,lucene-net,c,net 来源: https://codeday.me/bug/20191028/1953324.html