# Convert object/array datastructures to nested

**URL:** <https://discuss.elastic.co/t/convert-object-array-datastructures-to-nested/92594>\
**Category:** Logstash\
**Created:** [July 11, 2017, 7:41am UTC](https://discuss.elastic.co/t/convert-object-array-datastructures-to-nested/92594 "2017-07-11T07:41:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonasbareiss](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jonasbareiss](https://discuss.elastic.co/u/jonasbareiss)\
**Post date:** [July 11, 2017, 7:41am UTC](https://discuss.elastic.co/t/convert-object-array-datastructures-to-nested/92594/1 "2017-07-11T07:41:42Z")

</div>

Hi everyone,  
I have an elasticsearch index that was used as datastore, where only the source fields were used. Some data is in an object structure, but now I need to be able to aggregate on it. The array does not always have the same number of elements.

Is there any method to "convert" or copy over the fields, maybe with mutate.  
Or is the only possibility a Ruby script to cycle through the array

Here is the Rubydebug output of a data sample:

```auto
    "attributes" => {
        "articles" => {
                "code" => "articles",
            "children" => {
                "techData" => [
                    [0] {
                        "__identity" => "a25337ab-be66-dd0f-5fd2-5aa6f338697f",
                              "code" => "MATNR",
                           "sorting" => "",
                            "values" => {
                            "data" => {
                                "text" => "9999999"
                            }
                        },
                              "name" => "Artikelnummer",
                             "count" => "1",
                            "format" => "techData"
                    },
                    [1] {
                        "__identity" => "0607beaa-1bf9-4020-2f47-d2850c3546ae",
                              "code" => "PL_DYN_QUERSCHNITT",
                           "sorting" => "2",
                            "values" => {
                            "data" => {
                                "text" => "2,5"
                            }
                        },
                              "name" => "Leiterquerschnitt in mm²",
                             "count" => "1",
                            "format" => "techData"
                    },
                    [2] {
                        "__identity" => "dfd12f5a-77b6-e1c7-8655-12131883fe97",
                              "code" => "PL_DYN_DURCHMESSERAUSSENMINMAX",
                           "sorting" => "6",
                            "values" => {
                            "data" => {
                                "text" => "3.4 - 4.1"
                            }
                        },
                              "name" => "Außendurchmesser in mm",
                             "count" => "1",
                            "format" => "techData"
                    },
                    [3] {
                        "__identity" => "2ee54785-08ec-a9c3-35c6-a19903f1d49e",
                              "code" => "PL_COLOUR",
                           "sorting" => "8",
                            "values" => {
                            "data" => {
                                "__identity" => "fe3169e9-abee-44cc-5ffe-e8ca2ba13adb",
                                      "text" => "braun"
                            }
                        },
                              "name" => "Aderfarbe",
                             "count" => "1",
                            "format" => "techData"
                    }
                ]
            }
        }
    }
```

I would need to get just the "Code" or the "name", and the "[data][text]"

The output should be sth like this:

```auto
"techData":{
   "key": "MATNR"
   "value" : "9999999"
}
{
   "key": "PL_COLOUR"
   "value" : "braun"
}
```

I found this post:

> [@I would like to access nested data from an array](https://discuss.elastic.co/t/i-would-like-to-access-nested-data-from-an-array/71432/6):
>
> I think the major issue here is that the source application is sending essentially a hash in array form. If the counters element was: "counters": { "n\_lost\_packets": 0, "n\_sent\_bytes": 130852808 } instead of: "counters": [{ "name": "n\_lost\_packets", "value": 0 }, { "name": "n\_sent\_bytes", "value": 130852808 }] it would be simpler. If you want to programatically you need ruby filter since, in your case each hash contains a key under "key" and a value under "valu…

but I am not sure how to get all the needed data back

---

<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:** [August 8, 2017, 7:53am UTC](https://discuss.elastic.co/t/convert-object-array-datastructures-to-nested/92594/2 "2017-08-08T07:53:26Z")

</div>

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