'elasticearch aggregation by array size

I need a stats on elasticsearch. I can't make the request.

I would like to know the number of people per appointment.

appointment index mapping

{
  "id" : "383577",
  "persons" : [
    {
      "id" : "1",
    },
    {
      "id" : "2",
    }
  ]
}

what i would like

"buckets" : [
{
  "key" : "1", <--- appointment of 1 person
  "doc_count" : 1241891
},
{
  "key" : "2", <--- appointment of 2 persons
  "doc_count" : 10137
},
{
  "key" : "3", <--- appointment of 3 persons
  "doc_count" : 8064
}

]

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source