es聚合后,默认返回结构并不会显示参加聚合的文档的详情,在此记录可实现的两种方法
方法一:top_hits
GET items/_search?size=0
{
"aggs": {
"art_no_repeat": {
"terms": {
"field": "art_no",
"min_doc_count": 2,
"size": 20
},
"aggs": {
"top_art_no": {
"top_hits": {
"size": 10
}
}
}
}
}
}
方法二:collapse+inner_hits
GET items/_search?size=3
{
"query": {
"match": {
"art_no.keyword": "九尾狐鞋业&A01"
}
},
"collapse": {
"field": "art_no",
"inner_hits": {
"name": "top_item",
"size": 2
}
}
}