gpt4 book ai didi

elasticsearch - Elasticsearch 日期范围聚合

转载 作者:行者123 更新时间:2023-12-04 06:08:14 28 4
gpt4 key购买 nike

我有一个Json数据

"hits": [
{
"_index": "outboxprov1",
"_type": "deleted-connector",
"_id": "AHkuN5_iRGO-R5dtaOvz6w",
"_score": 1,
"_source": {
"user_id": "1a9d05586a8dc3f29b4c8147997391f9",
"deleted_date": "2014-08-02T04:55:04.509Z"
}
},
{
"_index": "outboxprov1",
"_type": "deleted-connector",
"_id": "Busk7MDFQ4emtL3x5AQyZA",
"_score": 1,
"_source": {
"user_id": "1a9d05586a8dc3f29b4c8147997391f9",
"deleted_date": "2014-08-02T04:58:31.440Z"
}
},
{
"_index": "outboxprov1",
"_type": "deleted-connector",
"_id": "4AN0zKe9SaSF1trz1IixfA",
"_score": 1,
"_source": {
"user_id": "1a9d05586a8dc3f29b4c8147997391f9",
"deleted_date": "2014-07-02T04:53:07.010Z"
}
}
]

我正在尝试编写聚合查询,以查找特定“deleted_date”范围内的记录。这是我的查询

{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"daily_team": {
"date_range": {
"field": "deleted_date",
"format": "YYYY-MM-DD",
"ranges": [
{
"from": "2014-08-02"
},
{
"to": "2014-08-02"
}
]
},
"aggs": {
"daily_team_count": {
"terms": {
"field": "user_id"
}
}
}
}
}
}

我的问题是在特定日期范围内没有获得正确数量的记录。当我输入任何日期时,我都会得到一些 doc_count 编号。我是 Elasticsearch 的新手。我不确定这是编写范围聚合查询的方式。请帮我解决这个问题。

最佳答案

我认为问题是您混淆了日期范围聚合的“从”和“到”,以及范围过滤器。范围过滤器默认包括日期(从和到)。但在 date_range 聚合中,包括每个范围的起始值并排除起始值。

在您的查询中,

{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"daily_team": {
"date_range": {
"field": "deleted_date",
"format": "YYYY-MM-DD",
"ranges": [
{
"from": "2014-08-02"
},
{
**"to": "2014-08-02"** -- > if you want to include 2014-08-02 date then do,
"to" : "2014-08-03" (increase date by one, so 08-02 is included)
}
]
},
"aggs": {
"daily_team_count": {
"terms": {
"field": "user_id"
}
}
}
}
}
}

我也遇到过这个问题,我想你的问题也是一样的。

仅供引用,请查看 link .

关于elasticsearch - Elasticsearch 日期范围聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25093995/

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