gpt4 book ai didi

elasticsearch - 获取所有时间date_histogram存储桶结果

转载 作者:行者123 更新时间:2023-12-03 01:19:44 24 4
gpt4 key购买 nike

我有以下查询,以使用Elasticsearch 7.1获取聚合。

{ 
"query": {
"bool": {
"filter": [
{
"bool": {
"must": [
{
"match": {
"viewedInFeed": true
}
}
]
}
}
]
}
},
"size": 0,
"aggs": {
"viewed_in_feed_by_day": {
"date_histogram": {
"field": "createdDate",
"interval" : "day",
"format" : "yyyy-MM-dd",
"min_doc_count": 1
}
}
}
}

结果大于10,000,由于 scroll无法用于聚合,因此我不确定如何工作。请参阅下面的响应。
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 10000,
"relation": "gte"
},
"max_score": null,
"hits": []
},
"aggregations": {
"viewed_in_feed_by_day": {
"buckets": [
{
"key_as_string": "2020-03-19",
"key": 1584576000000,
"doc_count": 3028
},
{
"key_as_string": "2020-03-20",
"key": 1584662400000,
"doc_count": 5384
},
{
"key_as_string": "2020-03-21",
"key": 1584748800000,
"doc_count": 3521
}
]
}
}
}

当使用 _count时,文档数大于10,000,即使没有 "min_doc_count": 1也不会返回结果,我仍然知道还有更多数据。

最佳答案

基于Jaspreet的评论,我建议以下内容:

  • 使用track_total_hits=true获取精确计数(自7.0起),同时保持size=0仅聚合。
  • 在运行直方图之前,请使用stats聚合获得更多见解。
  • GET dates/_search
    {
    "track_total_hits": true,
    "size": 0,
    "aggs": {
    "dates_insights": {
    "stats": {
    "field": "createdDate"
    }
    },
    "viewed_in_feed_by_day": {
    "date_histogram": {
    "field": "createdDate",
    "interval" : "month",
    "format" : "yyyy-MM-dd",
    "min_doc_count": 1
    }
    }
    }
    }

    屈服
    ...
    "hits" : {
    "total" : {
    "value" : 3,
    "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
    },
    "aggregations" : {
    "viewed_in_feed_by_day" : {
    "buckets" : [
    {
    "key_as_string" : "2020-01-01",
    "key" : 1577836800000,
    "doc_count" : 1
    },
    {
    "key_as_string" : "2020-02-01",
    "key" : 1580515200000,
    "doc_count" : 1
    },
    {
    "key_as_string" : "2020-03-01",
    "key" : 1583020800000,
    "doc_count" : 1
    }
    ]
    },
    "dates_insights" : {
    "count" : 3,
    ...
    "min_as_string" : "2020-01-22T13:09:21.588Z",
    "max_as_string" : "2020-03-22T13:09:21.588Z",
    ...
    }
    }
    ...

    关于elasticsearch - 获取所有时间date_histogram存储桶结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60794146/

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