为什么ElasticSearch只为dat_histogram聚合返回5个存储桶?

时间:2018-07-03 20:40:58

标签: elasticsearch

我有一个ElasticSearch索引,该索引充满了旧日志数据,我想按小时进行存储,以了解何时最活跃的时间是该数据的时间。 date_histogram聚合似乎非常适合此操作,但是我在确定如何使聚合产生5个以上的存储桶方面遇到问题。

该索引中约有7.25亿个文档,跨越大约7或8个月,因此每小时应该是几千个存储桶,但是当我使用以下查询正文时,我只会获得5个存储桶

{
    "query":{
        "match_all":{}
    },
    "aggs":{
        "events_per_hour":{
            "date_histogram":{
                "field":"timestamp",
                "interval":"hour"
            }
        }
    }
}

结果似乎跨越了正确的时间段,但是它迫使它进入了5个存储桶,而不是我期望的数千个

{
    "took": 276509,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 726450222,
        "max_score": 0,
        "hits": []
    },
    "aggregations": {
        "events_per_hour": {
            "buckets": [
                {
                    "key_as_string": "1970-01-18T13:00:00.000Z",
                    "key": 1515600000,
                    "doc_count": 51812791
                },
                {
                    "key_as_string": "1970-01-18T14:00:00.000Z",
                    "key": 1519200000,
                    "doc_count": 130819007
                },
                {
                    "key_as_string": "1970-01-18T15:00:00.000Z",
                    "key": 1522800000,
                    "doc_count": 188046057
                },
                {
                    "key_as_string": "1970-01-18T16:00:00.000Z",
                    "key": 1526400000,
                    "doc_count": 296038311
                },
                {
                    "key_as_string": "1970-01-18T17:00:00.000Z",
                    "key": 1530000000,
                    "doc_count": 59734056
                }
            ]
        }
    }
}

我尝试通过Google搜索该问题,但看起来可以将其添加到术语聚合中的size参数,但显然不适用于直方图,因此我尝试更改了search.max_buckets设置,但没有也可以。

有什么方法可以让ES将这些数据分割成我需要的数千个存储桶?还是我需要写一些东西来下载所有数据并在内存中手动拆分?

1 个答案:

答案 0 :(得分:1)

如果您将日期中的“ key_as_string”(1970-01-18T13:00:00.000)转换为新纪元,则会看到: 时代时间戳记:1515600 时间戳(以毫秒为单位):1515600000

如果您将1515600000译为当前日期,则会收到正确的日期(2018年1月10日,星期三,4:00:00 PM)

因此,看起来就像您发送了纪元,但以字段定义的毫秒的日期格式。

相关问题