# Logstash with Elasticsearch: Update the field which involves json object on the script section

**URL:** <https://discuss.elastic.co/t/logstash-with-elasticsearch-update-the-field-which-involves-json-object-on-the-script-section/132012>\
**Category:** Logstash\
**Created:** [May 16, 2018, 1:52am UTC](https://discuss.elastic.co/t/logstash-with-elasticsearch-update-the-field-which-involves-json-object-on-the-script-section/132012 "2018-05-16T01:52:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sivaa2017](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sivaa2017/32/31232_2.png) [@sivaa2017](https://discuss.elastic.co/u/sivaa2017)\
**Post date:** [May 16, 2018, 1:52am UTC](https://discuss.elastic.co/t/logstash-with-elasticsearch-update-the-field-which-involves-json-object-on-the-script-section/132012/1 "2018-05-16T01:52:25Z")

</div>

Initially, i have inserted the below data into elasticsearch  
{"id":1234,"name":"Siva","City":"Chennai"}

Currently, I am trying to update the above record by adding additional columns,  
{"phoneType":"Personal","PhoneNumber":"9976997620"}

but, I couldnt get the json value on the elasticsearch script section as the field "phone" is considered as json object and not String.  
Can anyone suggest that, how to retrieve the json field "phone" inside the script section of the elasticsearch output

input {  
kafka{  
topics =\> "topic2"  
bootstrap\_servers =\> "localhost:9092"  
}  
}  
filter {  
json {  
source =\> "message"  
target =\> "phone"  
}  
}  
output  
{  
elasticsearch {  
hosts =\> ["[http://localhost:9200](http://localhost:9200)"]  
index =\> "test\_index"  
document\_type =\> "test\_type1"  
document\_id =\> "1234"  
action =\> "update"  
scripted\_upsert =\> "true"  
script\_lang =\> "painless"  
script\_type =\> "inline"  
script =\> "  
if(ctx.\_source.phoneData == null) ctx.\_source.phoneData = [params.event.get('phone')];  
else if(ctx.\_source.phoneData != null) ctx.\_source.phoneData.add(params.event.get('phone'));  
"  
stdout{  
codec =\> rubydebug  
}  
}

---

<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:** [June 13, 2018, 1:52am UTC](https://discuss.elastic.co/t/logstash-with-elasticsearch-update-the-field-which-involves-json-object-on-the-script-section/132012/2 "2018-06-13T01:52:29Z")

</div>

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