在上篇文章中对src_ip_location字段进行分组并求count,得到的结果却是ES把结果字段进行了分词,没有达到预期的结果.
解决方案:在聚合的字段后面加keyword
SQL语法
ES语法
{
"from": 0,
"size": 0,
"_source": {
"includes": [
"src_ip_location.keyword",
"COUNT"
],
"excludes": []
},
"stored_fields": "src_ip_location.keyword",
"aggregations": {
"src_ip_location.keyword": {
"terms": {
"field": "src_ip_location.keyword",
"size": 1000,
"shard_size": 20000,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"COUNT(*)": {
"value_count": {
"field": "_index"
}
}
}
}
}
}