# How to write a scripted field for nested fileds in index pattern

**URL:** <https://discuss.elastic.co/t/how-to-write-a-scripted-field-for-nested-fileds-in-index-pattern/230252>\
**Category:** Kibana\
**Created:** [April 28, 2020, 9:13pm UTC](https://discuss.elastic.co/t/how-to-write-a-scripted-field-for-nested-fileds-in-index-pattern/230252 "2020-04-28T21:13:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sami88rosh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sami88rosh/32/67316_2.png) [@sami88rosh](https://discuss.elastic.co/u/sami88rosh)\
**Post date:** [April 28, 2020, 9:13pm UTC](https://discuss.elastic.co/t/how-to-write-a-scripted-field-for-nested-fileds-in-index-pattern/230252/1 "2020-04-28T21:13:07Z")

</div>

Hello guys, I want to write a scripted filed to get nested filed value.  
I want to get the pressure value for each doc(record). Is it possible to do in Kibana?  
My index is like this.

Thanks in advance!!

> {  
> "\_index": "process\_data",  
> "\_type": "\_doc",  
> "\_id": "UzFHVDM1MTAxMTk5QSAyMDAyMDAwOTUzN19TVDNBMjBfU1QzQTIwMTAwXzIwMjAtMDItMThUMTk6NDc6MzM=",  
> "\_version": 1,  
> "\_score": 1,  
> "\_source": {  
> "eid": "",  
> "line": "Line 1",  
> "equipment": "Equipment 1",  
> "ladderver": "",  
> "registrydate": "2020-02-18T19:47:33",  
> "registryutcdate": "2020-02-18T10:47:33",  
> "setupid": "",  
> "workid": "2345743",  
> "datas": [  
> {  
> "datas\_id": "001",  
> "name": "cycletime",  
> "value": "13.9"  
> }  
> ,  
> {  
> "datas\_id": "002",  
> "name": "machinetime",  
> "value": "10.7"  
> }  
> ,  
> {  
> **"datas\_id": "003",**  
> **"name": "pressure",**  
> **"value": "12.56"**  
> }  
> ]  
> }  
> }

---

<div class="post-metadata">

**Author:** ![sami88rosh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sami88rosh/32/67316_2.png) [@sami88rosh](https://discuss.elastic.co/u/sami88rosh)\
**Post date:** [April 29, 2020, 11:11am UTC](https://discuss.elastic.co/t/how-to-write-a-scripted-field-for-nested-fileds-in-index-pattern/230252/2 "2020-04-29T11:11:27Z")

</div>

I could do it with the following scripted field.

```auto
for(item in params._source.datas)
{
    if(item.name=='pressure'){
      return item.value;
   }
}
return 0;

```

---

<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 27, 2020, 11:11am UTC](https://discuss.elastic.co/t/how-to-write-a-scripted-field-for-nested-fileds-in-index-pattern/230252/3 "2020-05-27T11:11:32Z")

</div>

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