elasticsearch,lucene.net,nest,C#,.net,elasticsearch,Lucene.net,Nest" /> elasticsearch,lucene.net,nest,C#,.net,elasticsearch,Lucene.net,Nest" />

C# 在嵌套弹性搜索中按降序获取不同的术语

C# 在嵌套弹性搜索中按降序获取不同的术语,c#,.net,elasticsearch,lucene.net,nest,C#,.net,elasticsearch,Lucene.net,Nest,我正在尝试使用Nest Elastic搜索通过CarsSold descending获得前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;} } publi

我正在尝试使用Nest Elastic搜索通过CarsSold descending获得前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;}
 }
公共类生成
{
公共字符串MakeId{get;set;}
公共字符串MakeName{get;set;}
公共字符串地址{get;set;}
公共列表模型{get;set;}
}
公车
{
公共int Id{get;set;}
公共字符串CarsName{get;set;}
公共int CarsSold{get;set;}
}
我尝试使用以下代码,但值不是按CarsSold降序排序的:

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))
                        )
                    )
                )
            );
var cars=Client.Search(s=>s
.尺寸(0)
.聚合(a=>a
.Terms(“唯一”,t=>t
.Field(f=>f.Models.FirstOrDefault().CarsName)
.尺寸(10)
.聚合(a2=>a2
.Max(“authStats”,s1=>s1.Field(f=>f.Models.FirstOrDefault().CarsSold))
)
)
)
);
任何帮助都将不胜感激。
嗯,我尝试了使用聚合的Max和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")
                            )
                        )
                    )
                )
            );
var result=Client.Search(s=>s
.聚合(a=>a
.术语(“唯一”,te=>te
.Field(“cars.carsName”)
.尺寸(10)
.OrderDescending(“totalCount”)
.聚合(aa=>aa
.Max(“总计数”,ma=>ma
.Field(“cars.carsSold”)
)
)
)
)
);