[英]How to make aggregations on field basis in NEST and Elastic Search?
I would like to perform aggregation in Elastic Search using NEST which would mimic the below SQL query:我想使用 NEST 在 Elastic Search 中执行聚合,这将模仿以下 SQL 查询:
select region, bucket, count(dispositioncode)
from tbl
group by region, bucket
My attempt so far到目前为止我的尝试
var dispositionCodes = new TermsQuery
{
IsVerbatim = true,
Field = "trailstatus",
Terms = new string[] { "TR" }
};
ISearchResponse<TrailReportModel> searchResponse =
ConnectionToES.EsClient()
.Search<TrailReportModel>
(s => s
.Index(feedbackIndex)
.From(0)
.Size(RecordSize)
.Query(q => q.MatchAll()
.Aggregations(fa => fa
.Filter("disp_aggs", f => f.Filter(fd => dispositionCodes))
)
var result = ((Nest.SingleBucketAggregate)searchResponse.Aggregations["disp_aggs"]).DocCount;
This gives me the count for the entire records irrespective of Region and Bucket.这给了我整个记录的计数,而不考虑区域和存储桶。 But I am looking for the Count per Region and Bucket basis.
但我正在寻找每个区域和存储桶的计数。
How can I achieve this?我怎样才能做到这一点?
It is a bit difficult without a case to test, but you may want to use the Terms aggregation (in NEST ).没有案例来测试有点困难,但您可能希望使用术语聚合(在NEST中)。
With this, you could specify something like:有了这个,您可以指定如下内容:
.Aggregations(a => a
.Terms("group_by_region", t => t.Field("region"))
.Terms("group_by_bucket", t => t.Field("bucket")))
This answer may also help, it is a similar problem:)这个答案也可能有帮助,这是一个类似的问题:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.