# Average of list lengths in documents using Json Input

**URL:** <https://discuss.elastic.co/t/average-of-list-lengths-in-documents-using-json-input/171177>\
**Category:** Kibana\
**Created:** [March 6, 2019, 6:32pm UTC](https://discuss.elastic.co/t/average-of-list-lengths-in-documents-using-json-input/171177 "2019-03-06T18:32:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmccoy](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@nmccoy](https://discuss.elastic.co/u/nmccoy)\
**Post date:** [March 6, 2019, 6:32pm UTC](https://discuss.elastic.co/t/average-of-list-lengths-in-documents-using-json-input/171177/1 "2019-03-06T18:32:30Z")

</div>

I would like to take an average of lengths using the json input for a document.

Let's say the documents are structured as follows

```
{
  "@timestamp" : "<TIMESTAMP>",
  "items" : [
    { "a" : 1 },
    { "b" : 2 },
    { "c" : 13 }
  ]
}

```

Then i would like to make a visualisation to take the average length of all the `items`.

How would I set the aggregation and Json input?

I believe the Json Input would be:

```
{"script" : "doc['items'].value.length()" }

```

But when I choose average I have to choose a field, which I am trying to supply with the Json Input, i.e. the length of the `items` list to be averaged.

---

<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:** [April 3, 2019, 6:32pm UTC](https://discuss.elastic.co/t/average-of-list-lengths-in-documents-using-json-input/171177/2 "2019-04-03T18:32:31Z")

</div>

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