1、使用聚合索引,默認支持keyword類型。text需要修改配置,會影響效率
其中analyzer可有可無,看創建索引時如何配置的,沒有的話會報錯,加上即可
PUT mam_cloud_video_dev/_mapping/_doc?include_type_name=true
{
"properties": {
"name": {
"type": "text",
"fielddata": true,
"analyzer": "ik_max_word"
}
}
}
2、使用聚合語句
GET mam_cloud_video_dev/_search
{
"size": 0,
"aggs": {
"messages": {
"terms": {
"field": "name",
"size": 50
}
}
}
}
結果: