0
我想類似的查詢以下SQL查詢:如何在es中實現以下sql查詢?
select countryName, count(distinct(countryId)) as findCount from city group by countryName having findCount > 1
誰知道如何在ES實現?
感謝您的回答!
我想類似的查詢以下SQL查詢:如何在es中實現以下sql查詢?
select countryName, count(distinct(countryId)) as findCount from city group by countryName having findCount > 1
誰知道如何在ES實現?
感謝您的回答!
你應該這樣做有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
部分。
我有一個計數(distinct(countryId))函數,它似乎需要管道agge有過濾器計數 –
countryId和countryName之間有1:1的關係嗎?所以'count(distinct(countryId))== count(distinct(countryName))'對不對? – Val
我的數據計數(distinct(countryId))!= count(distinct(countryName)),所以也許使用min_doc_count是不正確的 –