# Help on getting query to count avg, min and max nestings

**URL:** <https://discuss.elastic.co/t/help-on-getting-query-to-count-avg-min-and-max-nestings/315768>\
**Category:** Elasticsearch\
**Created:** [October 4, 2022, 11:10am UTC](https://discuss.elastic.co/t/help-on-getting-query-to-count-avg-min-and-max-nestings/315768 "2022-10-04T11:10:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sreekanth](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@sreekanth](https://discuss.elastic.co/u/sreekanth)\
**Post date:** [October 4, 2022, 11:10am UTC](https://discuss.elastic.co/t/help-on-getting-query-to-count-avg-min-and-max-nestings/315768/1 "2022-10-04T11:10:04Z")

</div>

I have an index with one nested field. Some docs have 10 nested docs and a few may have thousands of nested docs.  
I want to find the average/min and max count of nested items count across the index.

**Sample data** : in this **ReferenceList** is a nested object. for docid=1, ReferenceList has 3 entires. In docid=2, ReferenceList has 1 entry.  
I am looking for some stats like  
min=1 , max =3 , Average=2

```auto
{
  {
  "docid": "1",
    "ReferenceList": [
      {
        "pos": 1,
        "txt": "data"
      },
      {
        "pos": 2,
        "txt": "data"
      },
      {
        "pos": 3,
        "txt": "data"
      }
    ]
  },
  {
   "docid": "2",
    "ReferenceList": [
      {
        "pos": 1,
        "txt": "termd"
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 1, 2022, 11:10am UTC](https://discuss.elastic.co/t/help-on-getting-query-to-count-avg-min-and-max-nestings/315768/2 "2022-11-01T11:10:20Z")

</div>

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