ElasticSearch学习笔记之二十六 嵌套桶聚合

* Nested Aggregation(嵌套聚合)
<https://blog.csdn.net/weixin_43430036/article/details/83349221#Nested_Aggregation_2>


<>Nested Aggregation(嵌套聚合)

Nested Aggregation是一个可以对嵌套对象文档进行聚合的单分组聚合。

举例来说 我们有一个产品的索引,每个产品有着不同的经销商和不同的价格. 映射如下:
PUT /index { "mappings": { "product" : { "properties" : { "resellers" : {
"type" : "nested", "properties" : { "name" : { "type" : "text" }, "price" : {
"type" : "double" } } } } } } }
产品根对象有一个嵌套数组对象resellers。
下面的聚合会返回产品的最低价格:
GET /_search { "query" : { "match" : { "name" : "led tv" } }, "aggs" : {
"resellers" : { "nested" : { "path" : "resellers" }, "aggs" : { "min_price" : {
"min" : { "field" : "resellers.price" } } } } } }
如你所见, nested aggregation需要定义嵌套对象在顶级对象的路径。我们可以在嵌入对象上定义任何类型的聚合。

响应如下:
{ ... "aggregations": { "resellers": { "doc_count": 0, "min_price": { "value":
350 } } } }

友情链接
ioDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信