# Kibana - Visualize an array with variable number of fields in each document

**URL:** <https://discuss.elastic.co/t/kibana-visualize-an-array-with-variable-number-of-fields-in-each-document/169198>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [February 20, 2019, 12:00pm UTC](https://discuss.elastic.co/t/kibana-visualize-an-array-with-variable-number-of-fields-in-each-document/169198 "2019-02-20T12:00:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vaibzz](https://avatars.discourse-cdn.com/v4/letter/v/c0e974/32.png) [@Vaibzz](https://discuss.elastic.co/u/Vaibzz)\
**Post date:** [February 20, 2019, 12:00pm UTC](https://discuss.elastic.co/t/kibana-visualize-an-array-with-variable-number-of-fields-in-each-document/169198/1 "2019-02-20T12:00:03Z")

</div>

I have an index pattern in my kibana with an array field. The array field contains variable number of strings in each document. I have to visualize the count of each string in all documents. I went through many articles, people recommend to use painless script in situations when we are trying to access array elements. But in my case I am unable to figure out what exactly should I do using painless because the size of array is not fixed so I can't extract array values in different variables.

Please Help me with this. Also suggest some other way of doing so apart from painless. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [February 20, 2019, 8:30pm UTC](https://discuss.elastic.co/t/kibana-visualize-an-array-with-variable-number-of-fields-in-each-document/169198/2 "2019-02-20T20:30:41Z")

</div>

You could use a Painless scripted field like this:

```auto
return params._source.foo.length;

```

Alternatively, you could index the length of the array as a separate field and visualize on that instead.

---

<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:** [March 20, 2019, 8:30pm UTC](https://discuss.elastic.co/t/kibana-visualize-an-array-with-variable-number-of-fields-in-each-document/169198/3 "2019-03-20T20:30:43Z")

</div>

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