# Logstash only insert fields in script

**URL:** <https://discuss.elastic.co/t/logstash-only-insert-fields-in-script/156803>\
**Category:** Logstash\
**Created:** [November 15, 2018, 8:09am UTC](https://discuss.elastic.co/t/logstash-only-insert-fields-in-script/156803 "2018-11-15T08:09:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![M.alsioufi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m.alsioufi/32/52269_2.png) [@M.alsioufi](https://discuss.elastic.co/u/M.alsioufi)\
**Post date:** [November 15, 2018, 8:09am UTC](https://discuss.elastic.co/t/logstash-only-insert-fields-in-script/156803/1 "2018-11-15T08:09:44Z")

</div>

hi  
I am using Logstash to query MySQL database and insert its data to Elasticsearch cluster.  
In my Elasticsearch output plugin I use a script like the following  
script =\> 'if (ctx.\_source.nameslist== null){  
ctx.\_source.nameslist= new ArrayList();  
}  
if(!ctx.\_source.nameslist.contains("%{name}")){  
ctx.\_source.nameslist.add("%{name}");  
}'  
However logstash only inserts the field I use in the scripts and does not insert the other fields to my Elasticsearch. Is this normal? Do I have to add all the fields in the script? I have a lot of fields that I only want to insert them with no change.

---

<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:** [December 13, 2018, 8:10am UTC](https://discuss.elastic.co/t/logstash-only-insert-fields-in-script/156803/2 "2018-12-13T08:10:00Z")

</div>

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