• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >云计算 > Elasticsearch之Nested Aggregation,elasticsearch

Elasticsearch之Nested Aggregation,elasticsearch

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含elasticsearch nested,elasticsearch,elasticsearch教程,elasticsearch官网,elasticsearch安装等服务器相关知识,网友希望可以进行参考

Elasticsearch之Nested Aggregation,elasticsearch


                                                  (这是一个小系列:请戳:Elasticsearch之Nested(嵌套)系列,查看其他nested相关文章)

             In the same way as we need to use the special nested query to gain access to nested objects at search time, the dedicated nested aggregation allows

 us to aggregate fields in nested objects:

  与在检索时需要使用特定的nested查询来接触nested object一样,特定的nested聚合同样能让我们对nested object内的字段进行聚合:

curl -XGET 'localhost:9200/my_index/blogpost/_search?search_type=count' -d '
{
  "aggs":{
     "comments":{①
	    "nested":{
		   "path":"comments"
		},
		"aggs":{
		   "by_month":{
		      "date_histogram":{②
			      "field":"comments.date",
				  "interval":"month",
				  "format":"yyyy-MM"
			  },
			  "aggs":{
			     "avg_stars":{
				    "avg":{③
					   "field":"comments.stars"
					}
				 }
			  }
		   }
		}
	 }
  }
}

①:The nested aggregation “steps down” into the nested comments object.

nested 聚合进入nested评论对象。

②:Comments are bucketed into months based on the comments.date field。

   评论基于comments.date字段聚合成月

③:The average number of stars is calculated for each bucket.

对于每一个簇,计算星级 的平均值。

The results show that aggregation has happened at the nested document level:

结果表明,聚合的确发生在nested文本层:

...
"aggregations": {
  "comments": {
     "doc_count": 4, 
     "by_month": {
        "buckets": [
           {
              "key_as_string": "2014-09",
              "key": 1409529600000,
              "doc_count": 1, 
              "avg_stars": {
                 "value": 4
              }
           },
           {
              "key_as_string": "2014-10",
              "key": 1412121600000,
              "doc_count": 3, 
              "avg_stars": {
                 "value": 2.6666666666666665
              }
           }
        ]
     }
  }
}

reverse_nested Aggregation

反嵌套聚合

 

A nested aggregation can access only the fields within the nested document. It can’t see fields in the root document or in a different 

nested document. However, we can step out of the nested scope back into the parent with a reverse_nested aggregation.

一个nested聚合只能接入nested文本内的字段,它不能看到根文本或者不同nested文本内的字段。但是,我们可以通过一个反嵌套聚合跳出nested局域进入父层。

For instance, we can find out which tags our commenters are interested in, based on the age of the commenter. The comment.age is

 a nested field, while the tags are in the root document:

比如我们基于评论者的年龄找出哪些标签是评论者感兴趣的。comment.age是一个nested字段,而tags位于根文本中:

curl -XGET 'localhost:9200/my_index/blogpost/_search?search_type=count' -d '
{
  "aggs":{
     "comments":{
	    "nested":{①
		   "path":"comments"
		},
		"aggs":{
		  "age_group":{
		      "histogram":{②
			     "field":"comments.age",
				 "interval":10
			  },
			  "aggs":{
			     "blogposts":{
				    "reverse_nested":{},③
					"aggs":{
					   "tags":{
					      "terms":{④
						     "field":"tags"
						  }
					   }
					}
				 }
			  }
		  }
		}
	  }
    }		
}

②:The histogram agg groups on the comments.age field, in buckets of 10 years.

histogram(直方图)聚合在comments.age字段上分组,每10年一组。

③:The reverse_nested agg steps back up to the root document.

reverse_nested聚合跳转回根文本。

④:The terms agg counts popular terms per age group of the commenter.

terms聚合计算每个年龄组的流行terms。

The abbreviated results show us the following:

下面是简化结果:

..
"aggregations": {
  "comments": {
     "doc_count": 4, 
     "age_group": {
        "buckets": [
           {
              "key": 20, 
              "doc_count": 2, 
              "blogposts": {
                 "doc_count": 2, 
                 "tags": {
                    "doc_count_error_upper_bound": 0,
                    "buckets": [ 
                       { "key": "shares",   "doc_count": 2 },
                       { "key": "cash",     "doc_count": 1 },
                       { "key": "equities", "doc_count": 1 }
                    ]
                 }
              }
           },
...

When to Use Nested Objects

何时使用nested 对象。

Nested objects are useful when there is one main entity, like our blogpost, with a limited number of closely related but less important entities, 

such as comments. It is useful to be able to find blog posts based on the content of the comments, and the nested query and filter provide for<

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Elasticsearch之Nested Query,elasticsearch
  • Elasticsearch之Nested Aggregation,elasticsearch
  • Elasticsearch之Nested Object Mapping,elasticsearch
  • Elasticsearch之Nested Sorting,elasticsearch
  • Elasticsearch之Nested(嵌套)系列,elasticsearch

相关文章

  • [Hive]Hive分区表新增字段,hive分区表新增字段
  • hive创建表语句详解,hive语句详解
  • ganglia安装教程,ganglia教程
  • 《转》Ubuntu14.04 openstack juno配置之 ceilometer遥测模块安装配置,《转》ubuntu14.04
  • Ceph集群磁盘没有剩余空间的解决方法,ceph集群
  • chinapub读书会第4期:企业级大数据应用与实践,chinapub读书会
  • Hadoop之——HBase笔记(补充),hadoophbase
  • 使用 ElasticSearch + LogStash + Kibana 来可视化网络流量,kibanaelasticsearch
  • Neutron数据库同步错误 NotImplementedError: No support for ALTER of constraints in SQLite dialect,sqlitealtertable
  • redhat7.0下mongodb主从搭配,redhat7.0mongodb

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • 深入理解Scala 标识符,命名和域,深入理解scala
    • hadoop学习笔记(三)——WIN7+eclipse+hadoop2.5.2部署,hadoopwin7
    • Hive 外部表 分区表,hive外部表分区表
    • hive FAILED: ParseException line 1:814 cannot recognize input near ‘;’ &lt;EOF&gt;’,hiveparseexception
    • 整套spark视频教程免费下载,还有Hadoop,sparkhadoop
    • 机器学习--k-近邻(kNN)算法案例,--k-knn
    • redis主从同步,redis主从
    • hadoop2企业级集群部署(DNS域名解析+NFS密钥共享+AWK批量复制),hadoop2awk
    • Understanding Cubert Concepts 之 BLOCK(一),cubertconcepts
    • 什么是Code Review,CodeReview

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有