使用topHit aggregation
{
"size": 0,
"query": {
"match_all": {}
},
"aggregations": {
"questionAgg": {
"terms": {
"field": "faqQuestion",
"size": 100
},
"aggregations": {
"faqFeedbackAgg": {
"terms": {
"field": "feedback",
"size": 2
}
},
"topHitCategory": {
"top_hits": {
"from": 0,
"size": 1
}
},
"faqMatchLevelAgg": {
"terms": {
"field": "faqMatchLevel",
"size": 3
}
},
"adoptCount": {
"cardinality": {
"field": "faqRelateId"
}
}
}
}
}
}