我想类似地查询以下SQL查询:
select countryName, count( distinct(countryId) ) as findCount from city group by countryName having findCount > 1
谁知道如何在es?
中实施感谢您的回答!
答案 0 :(得分:1)
您可以使用terms
聚合min_doc_count: 2
来执行此操作
{
"size": 0,
"aggs": {
"countries": {
"terms": {
"field": "countryName"
},
"aggs": {
"ids": {
"terms": {
"field": "countryId",
"min_doc_count": 2
}
}
}
}
}
}
请注意,countryName
字段应为not_analyzed
才能生效,或countryName
字段为multi-field且not_analyzed
部分。