elasticsearch中的filter与aggs
今天在ES上做了一个聚合,先过滤一个嵌套对象,再对另一个域做聚合,但是过滤似乎没有起作用
{
"size":0,
"filter":{
"nested":{
"path":"nna_risks",
"filter":{
"exists":{
"field":"nna_risks.ina_id"
}
}
}
},
"aggs":{
"level0":{
"terms":{
"script":"doc['inp_type'].value"
}
}
}
}
结果如下:
took: 47
timed_out: false
▾ _shards{}
total: 25
successful: 25
failed: 0
▾ hits{}
total: 31470
max_score: 0
▾ hits[]
▾ aggregations{}
▾ level0{}
doc_count_error_upper_bound: 0
sum_other_doc_count: 0
▾ buckets[]
key: ""
doc_count: 147617
key: ""
doc_count: 139434
key: ""
doc_count: 47220
key: ""
doc_count: 24580
key: ""
doc_count: 10148
从结果上看,聚合到的数目相加与Hits不相等;分析后发现,聚合的数据不是来源于过滤后,而是整个数据集;
修改方法, 不用过滤,而是用查询过滤
{
"size":0,
"query":{
"filtered":{
"filter":{
"nested":{
"path":"nna_risks",
"filter":{
"exists":{
"field":"nna_risks.ina_id"
}
}
}
}
}
},
"aggs":{
"level0":{
"terms":{
"script":"doc['inp_type'].value"
}
}
}
}
结果集:
took: 14
timed_out: false
▾ _shards{}
total: 25
successful: 25
failed: 0
▾ hits{}
total: 31617
max_score: 0
▾ hits[]
▾ aggregations{}
▾ level0{}
doc_count_error_upper_bound: 0
sum_other_doc_count: 0
▾ buckets[]
key: ""
doc_count: 18634
key: ""
doc_count: 7464
key: ""
doc_count: 2845
key: ""
doc_count: 1738
key: ""
doc_count: 936
或者在聚合体中过滤:
{
"size":0,
"aggs":{
"level0":{
"filter":{
"nested":{
"path":"nna_risks",
"filter":{
"exists":{
"field":"nna_risks.ina_id"
}
}
}
},
"aggs":{
"level1":{
"terms":{
"script":"doc['inp_type'].value"
}
}
}
}
}
}
结果为:
took: 36
timed_out: false
▾ _shards{}
total: 25
successful: 25
failed: 0
▾ hits{}
total: 375035
max_score: 0
▾ hits[]
▾ aggregations{}
▾ level0{}
doc_count: 31836
▾ level1{}
doc_count_error_upper_bound: 0
sum_other_doc_count: 0
▾ buckets[]
key: ""
doc_count: 18727
key: ""
doc_count: 7525
key: ""
doc_count: 2878
key: ""
doc_count: 1743
key: ""
doc_count: 963
elasticsearch中的filter与aggs的更多相关文章
- 如何在Elasticsearch中安装中文分词器(IK+pinyin)
如果直接使用Elasticsearch的朋友在处理中文内容的搜索时,肯定会遇到很尴尬的问题--中文词语被分成了一个一个的汉字,当用Kibana作图的时候,按照term来分组,结果一个汉字被分成了一组. ...
- 在Elasticsearch中查询Term Vectors词条向量信息
这篇文章有点深度,可能需要一些Lucene或者全文检索的背景.由于我也很久没有看过Lucene了,有些地方理解的不对还请多多指正. 更多内容还请参考整理的ELK教程 关于Term Vectors 额, ...
- 使用Hive或Impala执行SQL语句,对存储在Elasticsearch中的数据操作(二)
CSSDesk body { background-color: #2574b0; } /*! zybuluo */ article,aside,details,figcaption,figure,f ...
- ElasticSearch中的简单查询
前言 最近修改项目,又看了下ElasticSearch中的搜索,所以简单整理一下其中的查询语句等.都是比较基础的.PS,好久没写博客了..大概就是因为懒吧.闲言少叙书归正传. 查询示例 http:// ...
- elasticsearch中的mapping映射配置与查询典型案例
elasticsearch中的mapping映射配置与查询典型案例 elasticsearch中的mapping映射配置示例比如要搭建个中文新闻信息的搜索引擎,新闻有"标题".&q ...
- Elasticsearch query和filter的区别
1.关于Query context和filter context 查询语句的表现行为取决于使用了查询上下文方式还是过滤上下文方式. Query context:查询上下文,回答了“文档是如何被查询语句 ...
- Elasticsearch 中映射参数doc_values 和 fielddata分析比较
doc_values 默认情况下,大部分字段是索引的,这样让这些字段可被搜索.倒排索引(inverted index)允许查询请求在词项列表中查找搜索项(search term),并立即获得包含该词项 ...
- Logstash:把MySQL数据导入到Elasticsearch中
Logstash:把MySQL数据导入到Elasticsearch中 前提条件 需要安装好Elasticsearch及Kibana. MySQL安装 根据不同的操作系统我们分别对MySQL进行安装.我 ...
- ElasticSearch中的sort排序和filedData作用
默认情况下,ElasticSearch 会根据算分进行排序: 可以使用 sort API 指定排序的规则: POST /kibana_sample_data_ecommerce/_search { & ...
随机推荐
- ZOJ1003 Crashing Balloon
Crashing Balloon Time Limit: 2 Seconds Memory Limit: 65536 KB On every June 1st, the Children's ...
- JAVA Eclipse 教程
http://www.runoob.com/eclipse/eclipse-tutorial.html
- Linux下进程描述(1)—进程控制块【转】
转自:http://www.cnblogs.com/33debug/p/6705391.html 进程概念介绍 进程是操作系统对运行程序的一种抽象. • 一个正在执行的程序: • 一个正在计算机上执行 ...
- C++实现高斯滤波器
在matlab中,我们经常用到高斯滤波器,生成滤波器一般都是这样的函数psf = fspecial('gauss', GaussSize, sigma),但是在vs2010中用到的高斯滤波器不能自 ...
- Oracle基础 08 用户角色 user/role
--查询帐户的状态select username,account_status from dba_users where username='SCOTT'; --创建用户create user jo ...
- 利用php设置url转发 - 解决空间不提供子目录绑定功能的问题
由于很多新手都是使用的虚拟空间都是最便宜的那种,这空间一般不支持子目录绑定.但是很多朋友又想设置几个不同的二级域名访问不同的网站程序.于是大家找到了域名url转发,但是由于国家政策的原因,许多服务商暂 ...
- 简单unix 局域网的TCP会话
client.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <e ...
- java.lang.NumberFormatException: multiple points 异常
平时使用SimpleDateFormat的时候都是在单线程的情况下使用的,今天在改写别人的代码,发现每个类中都会写大量的SimpleDateFormat实例.作为一个程序特有的洁癖开始对代码进行优化. ...
- 厦门大学XMUNET+ ubuntu连接方法
编辑连接 输入用户名和密码就好了 ubuntu16.04
- centos 查看 arp
yum install tcpdump -y tcpdump arp :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ...