我刚打酱油去了,不好意思

ElasticSearch 给出指定时间区间 获取时间区间内所有数据 group by 某个字段 可以实现么?

Elasticsearch | 作者 eshty | 发布于2019年05月14日 | 阅读数:3698

ElasticSearch 给出指定时间区间 获取时间区间内所有数据 group by 某个字段 可以实现么?不需要分组的具体数据 只需要分组的字段
已邀请:

Ombres

赞同来自: eshty

{
"query": {
"bool": {
"must": [
{
"query_string": {
"qeury": "date:[2019-05-12 TO 2019-05-14]"
}
}
]
}
},
"aggs": {
"products": {
"terms": {
"field": "category",
"size": 5
}
}
}
}
基本上就这个思路吧,query写查询条件,aggs写聚合条件也就是所谓group by

laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net

赞同来自: eshty

借助:tophits 聚合实现,里面限定你想要的字段。

eshty - 这个人很懒

赞同来自:

查了文档 貌似top hits可以实现 有朋友有运用的例子么?

eshty - 这个人很懒

赞同来自:

类似于 SQL  select * from .. where time > .. and time < .. group by ..

要回复问题请先登录注册