Elasticsearch日期直方图报告,汇总条款 [英] Elasticsearch Date Histogram report with Terms aggregation

查看:831
本文介绍了Elasticsearch日期直方图报告,汇总条款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图巢插件查询弹性的搜索数据。我有一个基于字段的年度工作报告计数。目前,我已经使用这个日期直方图报告,以下是弹性的查询。

I'm trying Nest plugin for querying elastic search data. I have a yearly job count report based on a field. Currently I have used the date Histogram report for this and below is the elastic query.

POST insight/_search
{
  "size": "0",
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "(onet.familycode: 11)"
        }
      }
    }
  },
  "aggregations": {
    "jobcounts_by_year": {
      "date_histogram": {
        "field": "jobdate",
        "interval": "year",
        "format": "yyyy"
      },
      "aggregations": {
        "count_by_occupation_family": {
          "terms": {
            "field": "onet.family"
          }
        }
      }
    }
  }
}

等同巢查询

result = ElasticSearchClient.Instance.Search<Job>(s => s.Size(0)
                    .Query(query => query
                        .Filtered(filtered => filtered
                            .Query(q => q
                                .QueryString(qs => qs.Query(queryString)))))
                    .Aggregations(a => a
                        .DateHistogram("jobcounts_by_year", dt => dt
                            .Field(ElasticFields.JobDate)
                            .Interval("year")
                            .Format("yyyy")
                            .Aggregations(a1 => a1
                            .Terms("top_agg", t => t
                                .Field(criteria.GroupBy.GetElaticSearchTerm())
                                    .Exclude("NA|Unknown|Not available")
                                .Size(Constants.DataSizeToCompare)))
                         )));



一切都工作得很好,但现在的问题是遍历结果得到的值,对于正常聚集我M目前正在做它像下面

Everything works well, but now the problem is iterating over the result to get values, For normal aggregation I'm currently doing it like below

data = result.Aggs.Terms("top_agg").Items.Select(item =>
                new JobReportResult
                {
                    Group = item.Key,
                    Count = item.DocCount
                }).ToList();



但似乎巢不日期直方图桶桶支撑带。

But it seems Nest doesn't support buckets with in Date Histogram buckets.

如果我试图像下面我得到空引用异常。

If i tried like below I'm getting null reference exception.

result.Aggs.DateHistogram("jobcounts_by_year").Terms("top_agg")

看来,我们必须使用类似现在below.The D2具有IAggregation

It seems we have to use something like below.The d2 now has IAggregation

    var d1 = result.Aggs.DateHistogram("jobcounts_by_year").Items;
    var d2 =(TermsAggregator)d1[0].Aggregations["top_agg"];



但聚合属性未露出任何值。

But the Aggregation property is not exposing any values.

我在这里卡住了。有人可以让我知道我可以使用NEST

I'm stuck here. Can someone let me know how can I access buckets inside DateHistogram Buckets using NEST

在获得DateHistogram水桶内桶,

Regards,

推荐答案

试试这个

var dateHistogram = searchResponse.Aggs.DateHistogram("jobcounts_by_year");

foreach (var item in dateHistogram.Items)
{
    var bucket = item.Terms("top_agg");
}



希望这有助于。

Hope this helps.

这篇关于Elasticsearch日期直方图报告,汇总条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆