gpt4 book ai didi

elasticsearch - Elasticsearch 中的聚合日期范围过滤值

转载 作者:行者123 更新时间:2023-12-04 17:22:47 35 4
gpt4 key购买 nike

我需要根据日期过滤一组值(在此处添加字段),然后按 device_id 对其进行分组。所以我正在使用以下东西:

{
"aggs":{
"dates_between":{
"filter": {
"range" : {
"added" : {
"gte": "2014-07-01 00:00:00",
"lte" :"2014-08-01 00:00:00"
}
}
},
"aggs": {
"group_by_device_id": {
"terms": {
"field": "device_id"
}
}
}
}
}
}

这在执行查询时给我一个错误 "Failed to parse source"。这是正确的做法吗?

如果我只执行日期聚合,它会显示不在指定日期范围内的值

最佳答案

dates_between 的另一种方式是 group_by_device_id 的嵌套聚合

"aggs": {
"group_by_device_id": {
"terms": {
"field": "device_id"
},
"aggs": {
"dates_between": {
"filter": {
"range": {
"added": {
"gte": "2014-07-01 00:00:00",
"lte": "2014-08-01 00:00:00"
}
}
}
}
}
}
}

您还可以将过滤器移动到查询中:

{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"range": {
"added": {
"gte": "2014-07-01 00:00:00",
"lte": "2014-08-01 00:00:00"
}
}
}
}
},
"aggs": {
"group_by_device_id": {
"terms": {
"field": "device_id"
}
}
}
}

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

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