本文介绍了如何在es中实现以下sql查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想类似地查询以下SQL查询:
I want to query similarly the following SQL query:
select countryName, count( distinct(countryId) ) as findCount from city group by countryName having findCount > 1
谁知道如何在es中实现?
Who know how to implement in es ?
感谢您的回答!
推荐答案
您可以使用条款
聚合与 min_doc_count:2
像这样
You'd do this with a terms
aggregation with min_doc_count: 2
like this
{
"size": 0,
"aggs": {
"countries": {
"terms": {
"field": "countryName"
},
"aggs": {
"ids": {
"terms": {
"field": "countryId",
"min_doc_count": 2
}
}
}
}
}
}
请注意, countryName
字段应为 not_analyzed
,以使其正常工作,或 countryName
字段是,一个 not_analyzed
部分。
Note that the countryName
field should be not_analyzed
in order for this to work, or the countryName
field is a multi-field with a not_analyzed
part.
这篇关于如何在es中实现以下sql查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!