# Visualize based on grouped documents using element value

**URL:** <https://discuss.elastic.co/t/visualize-based-on-grouped-documents-using-element-value/229237>\
**Category:** Kibana\
**Created:** [April 22, 2020, 11:11am UTC](https://discuss.elastic.co/t/visualize-based-on-grouped-documents-using-element-value/229237 "2020-04-22T11:11:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abregman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abregman/32/63862_2.png) [@abregman](https://discuss.elastic.co/u/abregman)\
**Post date:** [April 22, 2020, 11:11am UTC](https://discuss.elastic.co/t/visualize-based-on-grouped-documents-using-element-value/229237/1 "2020-04-22T11:11:54Z")

</div>

Hey, assuming I have the following documents that represent passengers:

```auto
{‘name’: ‘Mario’, preferable_seats: [2,3,4], car: 2}
{‘name’: ‘Luigi’, preferable_seats: [1,4,5], car: 1, }
{‘name’: ‘Toad’, preferable_seats: [1, 2], car: 2, }

```

Now, this is what I have indexed in elasticsearch but when working with the data and creating visualizations in Kibana I would like to actually refer to cars. So basically I want for example to:

- Create a pie chart of the number of passengers in each car
- Show overall preferable seats per car. So for example, car 2 list will be: [1, 2, 3, 4]

Now to the question - what would be the best way to tackle this?: Create car documents prior to indexing the data or do it directly in Kibana? If in KIbana, it would be nice if someone could show me how for example I can do “Create a pie chart of the number of passengers in each car".

---

<div class="post-metadata">

**Author:** ![Luca\_Belluccini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luca_belluccini/32/33239_2.png) [@Luca\_Belluccini](https://discuss.elastic.co/u/Luca_Belluccini)\
**Post date:** [April 22, 2020, 11:30am UTC](https://discuss.elastic.co/t/visualize-based-on-grouped-documents-using-element-value/229237/2 "2020-04-22T11:30:01Z")

</div>

If you're going to index the documents as follows:

```auto
POST cars/_doc/1
{"name": "Mario", "preferable_seats": [2,3,4], "car": 2}

POST cars/_doc/2
{"name": "Luigi", "preferable_seats": [1,4,5], "car": 1 }

POST cars/_doc/3
{"name": "Toad", "preferable_seats": [1, 2], "car": 2 }

```

You can create a Kibana index pattern named `cars`.

If the number of distinct cars is not extremely high, the following visualizations should make it.

> [@abregman](#):
>
> Create a pie chart of the number of passengers in each car

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/5/551f8d2bf4adfe8a0498ca512be745dca3285b93.png)

> [@abregman](#):
>
> Show overall preferable seats per car. So for example, car 2 list will be: [1, 2, 3, 4]

This will show the number of preferences per car, per seat.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/2/12e9a7034ed3d93be8c2f33697b2ba838d1dd75f.png)

---

<div class="post-metadata">

**Author:** ![abregman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abregman/32/63862_2.png) [@abregman](https://discuss.elastic.co/u/abregman)\
**Post date:** [April 22, 2020, 11:57am UTC](https://discuss.elastic.co/t/visualize-based-on-grouped-documents-using-element-value/229237/3 "2020-04-22T11:57:43Z")

</div>

Amazing. Thank you very much for the detailed answer 🙂

---

<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:** [May 20, 2020, 11:57am UTC](https://discuss.elastic.co/t/visualize-based-on-grouped-documents-using-element-value/229237/4 "2020-05-20T11:57:46Z")

</div>

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