我的elasticsearch查询如下:
{
"size": 0,
"aggs": {
"group_by_name": {
"terms": {
"field": "Infos.InstanceInfo.Name.keyword",
"size": 1000
},
"aggs": {
"group_by_id": {
"terms": {
"field": "Infos.InstanceInfo.ID.keyword",
"size": 1000
},
"aggs": {
"tops": {
"top_hits": {
"size": 100,
"sort": {
"Infos.InstanceInfo.StartTime": "asc"
}
}
}
}
},
"count": {
"cardinality": {
"field": "Infos.InstanceInfo.ID.keyword"
}
}
}
}
}
}
很好,我有一个结果:
aggregations
==>group_by_name
======>buckets:
{key:name1}
=========>group_by_id
==============>buckets
{key:id1}
===============>docs
{doc1.StartTime:"2020-12-15T19:00:00"}
{doc2.StartTime:"2020-12-15T20:00:00"}
{doc3.StartTime:"2020-12-15T21:00:00"}
{key:id2}
===============>docs
{doc1.StartTime:"2020-12-15T09:00:00"}
{doc2.StartTime:"2020-12-15T11:00:00"}
{doc3.StartTime:"2020-12-15T11:30:00"}
{key:id4}
===============>docs
{doc1.StartTime:"2020-12-15T22:00:00"}
{doc2.StartTime:"2020-12-15T23:00:00"}
{doc3.StartTime:"2020-12-15T23:30:00"}
{key:name2}
=========>group_by_id
==============>buckets
{key:id5}
===============>docs
{doc1.StartTime:"2020-12-15T05:00:00"}
{doc2.StartTime:"2020-12-15T05:30:00"}
{doc3.StartTime:"2020-12-15T06:00:00"}
{key:id8}
===============>docs
{doc1.StartTime:"2020-12-15T01:00:00"}
{doc2.StartTime:"2020-12-15T01:00:15"}
{doc3.StartTime:"2020-12-15T02:00:00"}
{key:id9}
===============>docs
{doc1.StartTime:"2020-12-15T08:00:00"}
{doc2.StartTime:"2020-12-15T09:00:15"}
{doc3.StartTime:"2020-12-15T10:00:00"}
现在,我正试着把里面的桶分类 group_by_id
按值聚合 StartTime
对于第一个文档,要获得如下内容:
aggregations
==>group_by_name
======>buckets:
{key:name1}
=========>group_by_id
==============>buckets
{key:id4}
===============>docs
{doc1.StartTime:"2020-12-15T22:00:00"}
{doc2.StartTime:"2020-12-15T23:00:00"}
{doc3.StartTime:"2020-12-15T23:30:00"}
{key:id1}
===============>docs
{doc1.StartTime:"2020-12-15T19:00:00"}
{doc2.StartTime:"2020-12-15T20:00:00"}
{doc3.StartTime:"2020-12-15T21:00:00"}
{key:id2}
===============>docs
{doc1.StartTime:"2020-12-15T09:00:00"}
{doc2.StartTime:"2020-12-15T11:00:00"}
{doc3.StartTime:"2020-12-15T11:30:00"}
{key:name2}
=========>group_by_id
==============>buckets
{key:id9}
===============>docs
{doc1.StartTime:"2020-12-15T08:00:00"}
{doc2.StartTime:"2020-12-15T09:00:15"}
{doc3.StartTime:"2020-12-15T10:00:00"}
{key:id5}
===============>docs
{doc1.StartTime:"2020-12-15T05:00:00"}
{doc2.StartTime:"2020-12-15T05:30:00"}
{doc3.StartTime:"2020-12-15T06:00:00"}
{key:id8}
===============>docs
{doc1.StartTime:"2020-12-15T01:00:00"}
{doc2.StartTime:"2020-12-15T01:00:15"}
{doc3.StartTime:"2020-12-15T02:00:00"}
你知道吗?
1条答案
按热度按时间kkih6yb81#
请遵循以下步骤: