我有一个具有以下文件的弹性搜索索引
{
"id":1
"mainid ": "497940311988134801282012-04-10 ",
}
{
"id":2
"mainid ": "497940311988134801282012-04-10 ",
}
我正在寻找类似-example mysql table之类的查询
id mainid
1 497940311988134801282012-04-10
2 497940311988134801282012-04-10
3 497940311988134801282012-04-10
4 something different
select id ,mainid ,count(mainid) as county from wfcharges group by mainid,id having county>1;
在弹性搜索中,因为没有计数聚合函数在弹性中可用。我被困在这里。这就是我尝试过的。任何建议或在线资源。谢谢
GET /wfcharges/_search
{
"aggs" : {
"countfield" : {
"count" : { "field" : "mainid" }
}
}
}
答案 0 :(得分:2)
答案 1 :(得分:1)
此查询将完全满足您的需求:
GET /wfcharges/_search
{
"aggs": {
"countfield": {
"terms": {
"field": "mainid",
"min_doc_count": 2
}
}
}
}
它将通过mainid
字段进行汇总,并告诉该存储桶的最小文档数必须为2(大于1):