ES聚合查询实例
查询特定渠道分享数量最大的30个文章的uuid:
{
"size": ,
"query": {
"bool": {
"must": [
{
"terms": {
"ul_actType": [ ],
"boost":
}
},
{
"terms": {
"ul_distChannel": [
,
,
, ],
"boost":
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost":
}
},
"explain": false,
"aggregations": {
"aggs_targetId": {
"terms": {
"field": "ul_targetId",
"size": ,
"min_doc_count": ,
"shard_min_doc_count": ,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_term": "asc"
}
]
}
}
}
}
查询特定渠道30篇文章的阅读数,推荐数,点赞数,分享数:
{
"size": ,
"query": {
"bool": {
"must": [
{
"terms": {
"ul_targetId": [
"94a803d3e883f96fc236c136de7fca2a",
"dedff564f1e67d86fda44fb8dce6cbc5",
"1b5ae5c0cfe26374af883e87d2b2f7c0",
"3c5c5b3cc698aae419cad8d6eb02cbf2",
"a7886af3f7d46dce4e5396dce3ed2b97",
"35140f8d3f96bd48b3f6724c712150b0",
"84801260669eec369d18225c6e63b01b",
"10dc5b9bb733049a028b4ada6e7a4b84",
"3587229434114e2fc3b3380643239f21",
"93956578579740bc8b812eec57631f71",
"9b9e248c892e3127ddcf3d5a440ab7a6",
"4a9eb484d0595f210fbc49fdb1fb1eb5",
"42f47d23cc154a4a6baddd5192f74f9c",
"9b640b026fd85fe3eaa738dca483ff73",
"2085b778ae6627cb236ae3cd6ba08acf",
"3a0e3bab19b8d1902e1359a7d330f675",
"4a10a6f8ddd78ae47bf3ff79bbc4a929",
"83f179c72918e0ac424c6f08cb628922",
"c642a8b80a5f72b426c1c30547e34ae3",
"7d2994d2b17c331a4d14eb16362b41b7",
"eaff7777a93fe1cfd05ce83dac3a07c4",
"f239bd18ddb31a9b38305a3fa8135583",
"ba3f535eb515c2f5948c902aa78e6733",
"3fd4a262c96d17c2df22ede68c013fc8",
"7bc7e72fdfb2f89200a975d8bec3323e",
"a56fd1fc1cde98355cafb321bf6b7fa5",
"1a21061052d3c72c5bff7c658fc9e656",
"2cd32bc12d56168dc7143a756697a831",
"70881bbbed12c5930af37de3d4c8cb6f",
"8c66080ac50992e25a0a3b9f06eba89e"
],
"boost":
}
},
{
"terms": {
"ul_actType": [
,
,
, ],
"boost":
}
},
{
"terms": {
"ul_distChannel": [
,
,
, ],
"boost":
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost":
}
},
"explain": false,
"aggregations": {
"aggs_targetId": {
"terms": {
"field": "ul_targetId",
"size": ,
"min_doc_count": ,
"shard_min_doc_count": ,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_term": "asc"
}
]
},
"aggregations": {
"aggs_actType": {
"terms": {
"field": "ul_actType",
"size": ,
"min_doc_count": ,
"shard_min_doc_count": ,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_term": "asc"
}
]
}
}
}
}
}
}
聚合例子:
{
"query": {
"bool": {
"must": [
{
"terms": {
"ul_actType": [ ]
}
},
{
"terms": {
"ul_actFrom": [ ]
}
},
{
"wildcard": {
"ul_langMode": "*1*"
}
},
{
"range": {
"ul_addTime": {
"lt": ,
"gte":
}
}
}
],
"must_not": [
{
"wildcard": {
"ul_userId": "temp*"
}
},
{
"term": {
"ul_version.keyword": -
}
}
]
}
},
"size": ,
"aggregations": {
"aggs_targetId": {
"terms": {
"field": "ul_targetId",
"size": ,
"min_doc_count": ,
"order": [
{
"_count": "desc"
},
{
"_term": "asc"
}
]
},
"aggs": {
"rare_targetId": {
"bucket_selector": {
"buckets_path": {
"doc_count": "_count"
},
"script": {
"inline": "params.doc_count < 3000"
}
}
}
}
}
}
}
多字段聚合例子:(2字段)
{
"query": {
"bool": {
"must": [
{
"range": {
"image_count": {
"from": "",
"to": null,
"include_lower": false,
"include_upper": true,
"boost":
}
}
},
{
"term": {
"atype": {
"value": "",
"boost":
}
}
},
{
"term": {
"flag_pool": {
"value": "",
"boost":
}
}
},
{
"term": {
"flag_ql": {
"value": "",
"boost":
}
}
},
{
"term": {
"flag_off": {
"value": "",
"boost":
}
}
},
{
"terms": {
"domain": [
"goldenmob.com"
],
"boost":
}
},
{
"range": {
"add_time": {
"from": "",
"to": "2017-06-15",
"include_lower": true,
"include_upper": true,
"boost":
}
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost":
}
},
"size": ,
"aggregations": {
"agg_author_count": {
"terms": {
"field": "author"
},
"aggregations": {
"agg_cate": {
"terms": {
"field": "app_category"
}
}
}
}
}
}
多字段聚合例子:(3字段)
{
"query": {
"bool": {
"must": [
{
"range": {
"image_count": {
"from": "",
"to": null,
"include_lower": false,
"include_upper": true,
"boost":
}
}
},
{
"term": {
"atype": {
"value": "",
"boost":
}
}
},
{
"term": {
"flag_pool": {
"value": "",
"boost":
}
}
},
{
"term": {
"flag_ql": {
"value": "",
"boost":
}
}
},
{
"term": {
"flag_off": {
"value": "",
"boost":
}
}
},
{
"terms": {
"domain": [
"goldenmob.com"
],
"boost":
}
},
{
"range": {
"add_time": {
"from": "",
"to": "2017-06-15",
"include_lower": true,
"include_upper": true,
"boost":
}
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost":
}
},
"size": ,
"aggs": {
"agg_author_count": {
"terms": {
"field": "author"
},
"aggs": {
"agg_cate": {
"terms": {
"field": "app_category"
},
"aggs": {
"agg_lang": {
"terms": {
"field": "lang"
}
}
}
}
}
}
}
}
注意:这里如果要进行多个字段的聚合,需要注意第二个aggs的位置,是在第一个的terms之后,而不是在第一个agg_author_count之后. aggregations = aggs
JSON转CSV: https://json-csv.com/
ES聚合查询实例的更多相关文章
- es聚合查询语法
{ "size": 0, "query": { "bool": { "filter ...
- Es学习第九课, 聚合查询和复合查询
ES除了实现前几课的基本查询,也可以实现类似关系型数据库的聚合查询,如平均值sum.最小值min.最大值max等等 我们就用上一课的数据作为参考来举例 聚合查询 sum聚合 sum是一个求累加值的聚合 ...
- ES[7.6.x]学习笔记(十)聚合查询
聚合查询,它是在搜索的结果上,提供的一些聚合数据信息的方法.比如:求和.最大值.平均数等.聚合查询的类型有很多种,每一种类型都有它自己的目的和输出.在ES中,也有很多种聚合查询,下面我们看看聚合查询的 ...
- ElasticSearch(ES)使用Nested结构存储KV及聚合查询
自建博客地址:https://www.bytelife.net,欢迎访问! 本文为博客同步发表文章,为了更好的阅读体验,建议您移步至我的博客 本文作者: Jeffrey 本文链接: https://w ...
- es的查询、排序查询、分页查询、布尔查询、查询结果过滤、高亮查询、聚合函数、python操作es
今日内容概要 es的查询 Elasticsearch之排序查询 Elasticsearch之分页查询 Elasticsearch之布尔查询 Elasticsearch之查询结果过滤 Elasticse ...
- ES系列九、ES优化聚合查询之深度优先和广度优先
1.优化聚合查询示例 假设我们现在有一些关于电影的数据集,每条数据里面会有一个数组类型的字段存储表演该电影的所有演员的名字. { "actors" : [ "Fred J ...
- ElasticSearch 6.2 Mapping参数说明及text类型字段聚合查询配置
背景: 由于本人使用的是6.0以上的版本es,在使用发现很多中文博客对于mapping参数的说明已过时.ES6.0以后有很多参数变化. 现我根据官网总结mapping最新的参数,希望能对大家有用处. ...
- Django-model聚合查询与分组查询
Django-model聚合查询与分组查询 聚合函数包含:SUM AVG MIN MAX COUNT 聚合函数可以单独使用,不一定要和分组配合使用:不过聚合函数一般和group by 搭配使用 agg ...
- python全栈开发day68-ORM操作:一般操作、ForeignKey操作、ManyToManyField、聚合查询和分组查询、F查询和Q查询等
ORM操作 https://www.cnblogs.com/maple-shaw/articles/9403501.html 一.一般操作 1. 必知必会13条 <1> all(): 查询 ...
随机推荐
- Python-S9-Day114——Flask开始实战
01 今日内容概要 02 课前分享 03 内容回顾 04 路飞学城表结构(一) 05 路飞学城表结构(二) 06 路飞学城立即支付思路 07 今日作业 08 初识Flask 09 werkzug 10 ...
- 双网卡只有一个能ping通的解决办法
来源:http://blog.csdn.net/centerpoint/article/details/38542719 Linux默认启用了反向路由检查 如果2个网卡在一个Lan里面,那么服务器可能 ...
- [c++基础]3/5原则--拷贝构造函数+拷贝赋值操作符
/* * main.cpp * * Created on: Apr 7, 2016 * Author: lizhen */ #include <iostream> #include &qu ...
- 【转】Using Raycasts and Dynamically Generated Geometry to Create a Line of Sight on Unity3D
http://www.linkedin.com/pulse/using-raycasts-dynamically-generated-geometry-create-line-thomas José ...
- Jquery版放大镜效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【bzoj1266】[AHOI2006]上学路线route 最短路+最小割
题目描述 可可和卡卡家住合肥市的东郊,每天上学他们都要转车多次才能到达市区西端的学校.直到有一天他们两人参加了学校的信息学奥林匹克竞赛小组才发现每天上学的乘车路线不一定是最优的. 可可:“很可能我们在 ...
- eclipse快捷键补全
Eclipse中 补全快捷键 默认Alt+/ 但是每个人习惯有所不同 我需要来修改自己熟悉的快捷键 windows->preferences->General->keys将Conte ...
- 【SPOJ694】Distinct Substrings (SA)
求不相同子串个数 该问题等价于求所有后缀间不相同前缀的个数..也就是对于每个后缀suffix(sa[i]),将贡献出n-sa[i]+1个,但同时,要减去那些重复的,即为height[i],故答案 ...
- PE
不是projecteuler,我想说的是projecteuclid..似乎是一个有很多数学文献的网站..? PE541似乎是一道很有趣的题目,有一个暴力大概就是首先转化一下模型变成找\(\sum_{x ...
- kvm虚拟化实践
.环境初始化 [root@localhost ~]# hostnamectl set-hostname kvm-node1 [root@kvm-node1 ~]# sed -i '/SELINUX=/ ...