# Problem when splitting a nested JSON array

**URL:** <https://discuss.elastic.co/t/problem-when-splitting-a-nested-json-array/270864>\
**Category:** Elasticsearch\
**Created:** [April 21, 2021, 3:34pm UTC](https://discuss.elastic.co/t/problem-when-splitting-a-nested-json-array/270864 "2021-04-21T15:34:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedro\_gonzalez](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@pedro\_gonzalez](https://discuss.elastic.co/u/pedro_gonzalez)\
**Post date:** [April 21, 2021, 3:34pm UTC](https://discuss.elastic.co/t/problem-when-splitting-a-nested-json-array/270864/1 "2021-04-21T15:34:14Z")

</div>

Hi,

I have seen multiple thread talking about this problem but with some differences. I have the following log schema:

```auto
"messageId": 123,
"timestamp": "2020-09-14T03:35:37",
"extra": {
    "name": "typefood",
    "food_changes": [ {
         "property": "coca",
         "data_type": "experience"},
          {"property": "tea",
          "data_type": "amazing"
          }
    ]

```

I would like to get what you can see on "food\_changes" splitted into two different logs like this outcome:

```auto
    "message.id": 123,
    "timestamp": "2020-09-14T03:35:37",
    "extra.name": "typefood"
    "extra.food_changes.property": "coca"
    "extra.food_changes.data_type": "experience"

```

```auto
    "message.id": 123,
    "timestamp": "2020-09-14T03:35:37",
    "extra.name": "typefood"
    "extra.food_changes.property": "tea"
    "extra.food_changes.data_type": "amazing"

```

What I am trying is:  
filter {  
json {  
source =\> "message"  
}  
split {  
field =\> "[extra][food\_changes]"  
}  
mutate {  
add\_field =\>  
"[message][id]" =\> "%{[messageid]}

}

But it only shows in Kibana the fields for the first log...

```auto
"messageid": 123,
"timestamp": "2020-09-14T03:35:37",
"extra.name": "typefood"
"extra.food_changes.property": "coca"
"extra.food_changes.data_type": "experience"

```

not for the second log...

```auto
"messageid": 123,
"timestamp": "2020-09-14T03:35:37",
"extra.name": "typefood"
"extra.food_changes.property": "tea"
"extra.food_changes.data_type": "amazing"

```

Can someone please give me some insight?

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [April 21, 2021, 3:41pm UTC](https://discuss.elastic.co/t/problem-when-splitting-a-nested-json-array/270864/2 "2021-04-21T15:41:29Z")

</div>

What is your full logstash pipeline? Are you setting `document_id` to something or are you letting elasticsearch set the document id?

---

<div class="post-metadata">

**Author:** ![pedro\_gonzalez](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@pedro\_gonzalez](https://discuss.elastic.co/u/pedro_gonzalez)\
**Post date:** [April 21, 2021, 4:57pm UTC](https://discuss.elastic.co/t/problem-when-splitting-a-nested-json-array/270864/3 "2021-04-21T16:57:05Z")

</div>

Hi Leandro,

@leandrojmp . Yes, I am letting elasticsearch to set the document id.

with "full logstash pipeline", do you mean the logstash.yml or where my config to ingest the logs I pasted before is?

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [April 21, 2021, 8:40pm UTC](https://discuss.elastic.co/t/problem-when-splitting-a-nested-json-array/270864/4 "2021-04-21T20:40:18Z")

</div>

Your full pipeline configuration, you shared only part of it, you need to share the complete pipeline with the inputs, filters and outputs.

---

<div class="post-metadata">

**Author:** ![pedro\_gonzalez](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@pedro\_gonzalez](https://discuss.elastic.co/u/pedro_gonzalez)\
**Post date:** [April 22, 2021, 5:59pm UTC](https://discuss.elastic.co/t/problem-when-splitting-a-nested-json-array/270864/5 "2021-04-22T17:59:15Z")

</div>

Hi @leandrojmp,

Thank you very much for your willingness to help. I made some changes compared to what I saw [here](https://discuss.elastic.co/t/split-nested-json-array/147969) and it worked. The problem of my real log schema is that it has few nested JSON arrays at different levels that's why it was a bit more complex than what you can see here:

> [@Split nested json array](https://discuss.elastic.co/t/split-nested-json-array/147969):
>
> I would like to to retrieve every element in below JSON to be a field so as to visualize in kibana by applying metrics in dashboard. { "message": "{"SegmentId":4,"VectorList":[{"LocalizationId":60,"ServiceId":1,"Date":"2018-09-10T00:00:00","IsAvailable":true,"FreeTermCount":80,"SegmentFreeTermCount":80,"FilterValue":null},{"LocalizationId":60,"ServiceId":2,"Date":"2018-09-10T00:00:00","IsAvailable":true,"FreeTermCount":21,"SegmentFreeTermCount":21,"FilterValue":42},{"LocalizationId":60,"Servi…

Thank you Leandro again.

---

<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, 2021, 5:59pm UTC](https://discuss.elastic.co/t/problem-when-splitting-a-nested-json-array/270864/6 "2021-05-20T17:59:33Z")

</div>

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