这个问题非常简单,在Elasticserch聚合中是否有相当于来自MongoDB聚合框架的$ unwind操作?
答案 0 :(得分:0)
要注意的重要一点是,与展开相比,ElasticSearch聚合不会重建这些文档,而是将聚合结果划分为存储桶。其余的解析工作将强加给客户。
示例,此查询:
{
"size": 0,
"aggregations": {
"array_aggregation": {
"terms": {
"field": "array_items",
"size": 10
},
"aggregations": {
"other_field_aggregation": {
"terms": {
"field": "some_other_field",
"size": 10
}
}
}
}
}
}
结果:
{
"took": 59,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 163,
"max_score": 0,
"hits": []
},
"aggregations": {
"array_aggregation": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "itemA",
"doc_count": 3858,
"other_field_aggregation": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "fieldA",
"doc_count": 3858
},
{
"key": "fieldB",
"doc_count": 4050
}
]
}
},
{
"key": "itemB",
"doc_count": 3858,
"other_field_aggregation": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "fieldA",
"doc_count": 3858
},
.
.
.
]
}
},
.
.
.
]
}
}
}
这不是最好的解决方案,但可以成为一个好的起点。