Elastic search Group by count for particular field

I have a elastic search index with following documents

        {
           "id":1
          "mainid  ": "497940311988134801282012-04-10  ",
         
        }
    
      {
           "id":2
          "mainid  ": "497940311988134801282012-04-10  ",
          
        }

I am looking to have a query similar like -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;`

in elastic search ,as there is no count aggregate function is available in elastic .I am stuck here.This is what ,I have tried. Any suggestions or online resources ??.Thanks

    GET /wfcharges/_search
    {
        "aggs" : {
            "countfield" : {
                "count" : { "field" : "mainid" }
            }
        }
    }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.