gpt4 book ai didi

elasticsearch - 如何在date_histogram聚合上放置大小

转载 作者:行者123 更新时间:2023-12-03 01:42:29 31 4
gpt4 key购买 nike

我在elasticsearch中执行查询。我需要为索引中表示的每个月的属性“end_date_ut”(类型为Date,格式为dateOptionalTime)的命中次数。
为此,我正在使用date_histogram聚合。

我的查询如下:

GET inc/_search
{
"size": 0,
"aggs": {
"appli": {
"date_histogram": {
"field": "end_date_ut",
"interval": "month"
}
}
}
}

这是结果的一部分:
"hits": {
"total": 517478,
"max_score": 0,
"hits": []
},
"aggregations": {
"appli": {
"buckets": [
{
"key_as_string": "2009-08-01T00:00:00.000Z",
"key": 1249084800000,
"doc_count": 0
},
{
"key_as_string": "2009-09-01T00:00:00.000Z",
"key": 1251763200000,
"doc_count": 1
},
{
"key_as_string": "2009-10-01T00:00:00.000Z",
"key": 1254355200000,
"doc_count": 2362
},
{
"key_as_string": "2009-11-01T00:00:00.000Z",
"key": 1257033600000,
"doc_count": 5336
},
{
"key_as_string": "2009-12-01T00:00:00.000Z",
"key": 1259625600000,
"doc_count": 7536
},
{
"key_as_string": "2010-01-01T00:00:00.000Z",
"key": 1262304000000,
"doc_count": 8864
}

问题是我的存储桶太多(结果)。当我使用“术语聚合”时,我没有任何问题,因为可以设置大小,但是使用“date_histogram聚合”时,我找不到限制查询结果的方法。

最佳答案

我建议使用min_doc_count仅包含具有数据的存储桶,即具有0个文档的存储桶不会在响应中返回。

GET inc/_search
{
"size": 0,
"aggs": {
"appli": {
"date_histogram": {
"field": "end_date_ut",
"interval": "month",
"min_doc_count": 1 <--- add this
}
}
}
}

如果可以,您还可以添加 range查询,以限制运行聚合的时间间隔。

关于elasticsearch - 如何在date_histogram聚合上放置大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46424311/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com