# How to correctly use json fields?

**URL:** <https://discuss.elastic.co/t/how-to-correctly-use-json-fields/244811>\
**Category:** Kibana\
**Created:** [August 13, 2020, 7:04am UTC](https://discuss.elastic.co/t/how-to-correctly-use-json-fields/244811 "2020-08-13T07:04:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jde](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@jde](https://discuss.elastic.co/u/jde)\
**Post date:** [August 13, 2020, 7:04am UTC](https://discuss.elastic.co/t/how-to-correctly-use-json-fields/244811/1 "2020-08-13T07:04:03Z")

</div>

Hello,

I have an index like that :

![screenshot](https://us1.discourse-cdn.com/elastic/original/3X/2/5/251a95814a4d9ff98ab3cc69690e4a985b1991a2.png)

I have an ID which could have a list of detail contact.  
In my vizualisation, I try to display the number of contacts per channel.

![2020-08-13_08h57_45](https://us1.discourse-cdn.com/elastic/original/3X/5/4/54ba2b71efdd95b62f48b0bc8b761a2a16c1331e.png) ![2020-08-13_08h58_00](https://us1.discourse-cdn.com/elastic/original/3X/d/e/dedcddb69f6f983f50adcf177b069000ae859cad.png)

 ![screenshot2](https://us1.discourse-cdn.com/elastic/original/3X/a/8/a81a044d9f637daff7530c7bc3c0b0f02a462237.png)

The result is 2 SMS and 2 EMAIL whereas i was expecting 1 SMS and 1 EMAIL.

Moreover, I don't understand in the discover, why the field details\_contact.jour\_contact is extracted from the json document and not the other fields.

Any idea ?

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [August 13, 2020, 7:08am UTC](https://discuss.elastic.co/t/how-to-correctly-use-json-fields/244811/2 "2020-08-13T07:08:41Z")

</div>

The problem is Kibana aggregations don't support nested arrays like this. For Kibana all of those fields are flattened like this:

```auto
{
  "details_contacts.canal_contact": ["EMAIL", "SMS"],
  "details_contacts.nb_contacts": [1, 1]
}

```

This means the association between `nb_contacts` and `canal_contact` is lost. If you want to visualize your data with Kibana, you should split up your documents to just have a single `details_contacts` per document - then the aggregation will work as expected.

---

<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:** [September 10, 2020, 7:08am UTC](https://discuss.elastic.co/t/how-to-correctly-use-json-fields/244811/3 "2020-09-10T07:08:58Z")

</div>

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