我知道Elasticsearch支持使用分段的子聚合(其中分段聚合可以具有分段或度量子聚合)。使用度量标准聚合无法进行子聚合。可能这是有道理的,但这是用例。
我有term aggregation作为父母。并使用另一个term
聚合作为它的子级。子term
具有top_hits
类型的子聚合。 top_hits
是度量标准聚合,因此无法进行任何子聚合。现在需要将avg
聚合包括在内。给定top_hits
是聚合树中的最后一个聚合,因为avg
是一个度量聚合,所以不能将top_hits
作为子节点。
以下是所需的聚合级别。 (当然,它是无效的,因为top_hits
是一个度量聚合,对avg
聚合也是如此。
{
"aggregations": {
"top_makes": {
"terms": {
"field": "make"
},
"aggregations": {
"top_models": {
"terms": {
"field": "model"
},
"aggregations": {
"top_res": {
"top_hits": {
"_source": {
"include": [
"model",
"color"
]
},
"size": 10
}
}
}
}
},
"aggregations": {
"avg_length": {
"avg": {
"field": "vlength"
}
}
}
}
}
}
解决此问题的解决方法或解决方法是什么?
答案 0 :(得分:2)
我认为这会有效,验证..
{
"aggregations": {
"top_makes": {
"terms": {
"field": "make"
},
"aggregations": {
"top_models": {
"terms": {
"field": "model"
},
"aggregations": {
"top_res": {
"top_hits": {
"_source": {
"include": [
"model",
"color"
]
},
"size": 10
}
}
},
"avg_length": {
"avg": {
"field": "vlength"
}
}
}
}
}
}
}
关键是您可以为父聚合提供一个或多个sibbling(子聚合)。