# Prevent upsert to merge internal objects in logstash configuration

**URL:** <https://discuss.elastic.co/t/prevent-upsert-to-merge-internal-objects-in-logstash-configuration/148061>\
**Category:** Logstash\
**Created:** [September 11, 2018, 6:45am UTC](https://discuss.elastic.co/t/prevent-upsert-to-merge-internal-objects-in-logstash-configuration/148061 "2018-09-11T06:45:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yalpanian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yalpanian/32/35573_2.png) [@yalpanian](https://discuss.elastic.co/u/yalpanian)\
**Post date:** [September 11, 2018, 6:45am UTC](https://discuss.elastic.co/t/prevent-upsert-to-merge-internal-objects-in-logstash-configuration/148061/1 "2018-09-11T06:45:27Z")

</div>

consider this record is stored in elastic search :

```
 { 
"id" : 1
"Name" : "a",
"Obj" : { "old" : 123 }
}

```

and i want to update that record by this :

```
{
"id" : 1
"Family" : "b",
"Obj" : { "new": 321 }
}

```

finally i want to this record to be exist in elastic :

```
 {
"id" : 1
"Name" : "a",
"Family" : "b",
"Obj" : { "new" : 321 }
}

```

but i've got this in real :

```
 {
"id" : 1
"Name" : "a",
"Family" : "b",
"Obj" : { **"old": 123** , "new" : 321 }
}

```

my logstash config is :

```
{
...
output {
  stdout {}
  elasticsearch { 
	hosts => ["localhost:9200"]
	index => "test" 
	action => "update"
	doc_as_upsert => true
	document_id => "%{id}"
  }
}

```

i even tried to remove that field ( Obj ) by script :

```
...
action => "update"
doc_as_upsert => true
**script => "ctx._source.remove('Obj')"**...

```

but it removed after update action and this record will appear in elastic :

```
 {
"id" : 1
"Name" : "a",
"Family" : "b"
}

```

and replacement the field by script did not work :

```
...
action => "update"
doc_as_upsert => true
**script => "ctx._source.Obj = doc[Obj]"**...

```

got this error in logstash :  
`Variable [Obj] is not defined`  
is there any idea to prevent upsert operation from merge obj field ?

---

<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:** [October 9, 2018, 6:45am UTC](https://discuss.elastic.co/t/prevent-upsert-to-merge-internal-objects-in-logstash-configuration/148061/2 "2018-10-09T06:45:31Z")

</div>

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