# Scripted fields and nested

**URL:** <https://discuss.elastic.co/t/scripted-fields-and-nested/193587>\
**Category:** Kibana\
**Created:** [August 2, 2019, 3:52pm UTC](https://discuss.elastic.co/t/scripted-fields-and-nested/193587 "2019-08-02T15:52:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![popopo](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@popopo](https://discuss.elastic.co/u/popopo)\
**Post date:** [August 2, 2019, 3:52pm UTC](https://discuss.elastic.co/t/scripted-fields-and-nested/193587/1 "2019-08-02T15:52:30Z")

</div>

Hi everyone,

I'm having trouble using scripted fields in Kibana...  
Here's my mapping:

```
{
  "mappings": {
    "_doc": {
      "properties": {
        "modules": { 
          "type": "nested",
          "properties": {
            "value": { "type": "string" },
            "criticity": { "type": "number" }
          }
        },
       "delta":"integer"
      }
    }
  }
}

```

What I'd like to do is display in a data table the following value:  
`doc['delta'].value * doc['modules.criticity'].value`

In my table, I split the rows on the _Term_ **modules.value.keyword**  
So everything's OK except for the criticity value because it does not return the criticity associated to the module value.

Anyone might have a clue on what I am missing? I think I understood why the result is bad, but I have no idea on how to achieve that...

Thanks everybody !

---

<div class="post-metadata">

**Author:** ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)\
**Post date:** [August 2, 2019, 7:06pm UTC](https://discuss.elastic.co/t/scripted-fields-and-nested/193587/2 "2019-08-02T19:06:41Z")

</div>

Hi @popopo,

Kibana doesn't yet support [nested types](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html), but it is one of our most popular feature requests. There's a [Github issue](https://github.com/elastic/kibana/issues/1084) you may be interested in following, which has more detail and discussion on this topic.

In the meantime, your best bet would be to extract those `modules` (if you are able) into separate fields in the document, rather than nesting them

---

<div class="post-metadata">

**Author:** ![popopo](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@popopo](https://discuss.elastic.co/u/popopo)\
**Post date:** [August 5, 2019, 6:20am UTC](https://discuss.elastic.co/t/scripted-fields-and-nested/193587/3 "2019-08-05T06:20:04Z")

</div>

Hi @lukeelmers,

I'm not sure I understand correctly. What do you mean by extracting these modules into separate fields in the document ?

Do you mean separate my message:

```
{
    "name":"20124",
    "timestamp":"2019-08-02T11:00:00",
    "insertions":30,
    "deletions":75,
    "modules":[
        {
            "value":"toto",
            "criticity":1
        },
        {
            "value":"tata",
            "criticity":2
        },
        {
            "value":"titi",
            "criticity":3
        }
    ]
}

```

into several messages:

```
    {  
    "name":"20124",
    "timestamp":"2019-08-02T11:00:00",
    "insertions":30,
    "deletions":75,
    "modules":"toto",
    "criticity":1
}

{  
    "name":"20124",
    "timestamp":"2019-08-02T11:00:00",
    "insertions":30,
    "deletions":75,
    "modules":"tata",
    "criticity":2
}

{  
    "name":"20124",
    "timestamp":"2019-08-02T11:00:00",
    "insertions":30,
    "deletions":75,
    "modules":"titi",
    "criticity":3
}

```

Like this ?

---

<div class="post-metadata">

**Author:** ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)\
**Post date:** [August 5, 2019, 3:32pm UTC](https://discuss.elastic.co/t/scripted-fields-and-nested/193587/4 "2019-08-05T15:32:37Z")

</div>

Yes exactly! Either separating into separate documents as you've done above, or if it is for some reason important for them to be in the same document and the module values are static, you could alternatively do:

```auto
    "name":"20124",
    "timestamp":"2019-08-02T11:00:00",
    "insertions":30,
    "deletions":75,
    "modules.toto.criticity": 1,
    "modules.tata.criticity": 2,
    "modules.titi.criticity": 3,

```

But generally I'd recommend going with the separate document approach from your example above. My example here only makes sense if you have a limited number of fixed module values.

---

<div class="post-metadata">

**Author:** ![popopo](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@popopo](https://discuss.elastic.co/u/popopo)\
**Post date:** [August 6, 2019, 5:34am UTC](https://discuss.elastic.co/t/scripted-fields-and-nested/193587/5 "2019-08-06T05:34:35Z")

</div>

Thanks.

It works indeed ! I can't put static values because the number of modules can change.  
Anyway thanks for your help !

---

<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 3, 2019, 5:34am UTC](https://discuss.elastic.co/t/scripted-fields-and-nested/193587/6 "2019-09-03T05:34:36Z")

</div>

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