Nested Aggregation(嵌套聚合)
译文链接 : http://www.apache.wiki/display/Elasticsearch(修改该链接为 ApacheCN 对应的译文链接)
Nested Aggregation
一个特殊的single bucket(单桶)聚合,可以聚合嵌套的文档
例如,假设我们有一个产品的索引,并且每个产品都包含一个分销商列表——每个产品都有自己的价格。映射可能是:
{..."product" : {"properties" : {"resellers" : { #1"type" : "nested","properties" : {"name" : { "type" : "text" },"price" : { "type" : "double" }}}}}}
#1 resellers是一个在product对象下保存嵌套文档的数组。
以下汇总将返回可以购买的最低价格产品:
{"query" : {"match" : { "name" : "led tv" }},"aggs" : {"resellers" : {"nested" : {"path" : "resellers"},"aggs" : {"min_price" : { "min" : { "field" : "resellers.price" } }}}}}
如上所述,嵌套聚合需要顶层文档中嵌套文档的路径。 然后可以在这些嵌套文档上定义任何类型的聚合。
响应结果:
{"aggregations": {"resellers": {"min_price": {"value" : 350}}}}
