Average of list lengths in documents using Json Input

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.

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