弹性搜索平均值超过日期直方图桶 [英] Elasticsearch average over date histogram buckets

查看:107
本文介绍了弹性搜索平均值超过日期直方图桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ElasticSearch中编入了一堆索引的文档,我需要获取以下数据:

I've got a bunch of documents indexed in ElasticSearch, and I need to get the following data:

对于每个月,获取文档的平均数<

For each month, get the average number of documents per working day of the month (or if impossible, use 20 days as the default).

我已将我的数据汇总到几个月的桶中,使用日期直方图聚合。我试图嵌套一个 stats bucket,但是这个聚合使用从文档字段中提取的数据,而不是从父级桶中提取数据。

I already aggregated my data into months buckets using the date histogram aggregation. I tried to nest a stats bucket, but this aggregations uses data extracted from the document's field, not from the parent bucket.

这是我的查询到目前为止:

Here is my query so far:

{
    "query": {
        "match_all": {}
    },
    "aggs": {
        "docs_per_month": {
            "date_histogram": {
                "field": "created_date",
                "interval": "month",
                "min_doc_count": 0
            }
            "aggs": {
                '???': '???'
            }
        }
    }
}

编辑

为了让我的问题更清楚,我需要的是:

To make my question clearer, what I need is:


  • 获取为该月份创建的文档数量(由于 date_histogram 聚合)已经完成的文档数量

  • 获取该月份的工作天数

  • 划分第一个到第二个。

  • Get the total of numbers of documents created for the month (which is already done thanks to the date_histogram aggregation)
  • Get the number of working days for the month
  • Divide the first by the second.

推荐答案

你基本上需要的就是这样的(不起作用,因为它不是一个可用的功能):

What you basically need is something like this (which doesn't work, as it's not an available feature):

{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "docs_per_month": {
      "date_histogram": {
        "field": "date",
        "interval": "month",
        "min_doc_count": 0
      },
      "aggs": {
        "average": {
          "avg": {
            "script": "doc_count / 20"
          }
        }
      }
    }
  }
}

它不工作因为没有办法从父汇总中访问 doc_count

It doesn't work because there is not way of accessing the doc_count from the "parent" aggregation.

但是,这将是可能的在Elasticsearch的2.x分支中,目前正在积极开发: https://github.com/elastic/elasticsearch/issues/8110
这个新功能将在结果上添加第二层操纵(buckets)的一个聚合,它不仅仅是你的usecase,而是很多其他的。

But, this will be possible in the 2.x branch of Elasticsearch and, at the moment, it's being actively developed: https://github.com/elastic/elasticsearch/issues/8110 This new feature will add a second layer of manipulation over the results (buckets) of an aggregation and it's not only your usecase, but many others.

除非你想尝试某些想法在那里或在您的应用程序中执行自己的计算,您需要等待此功能。

Unless you want to try some ideas out there or perform your own calculations in your app, you need to wait for this feature.

这篇关于弹性搜索平均值超过日期直方图桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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