# Confused with Update API's

**URL:** https://discuss.elastic.co/t/confused-with-update-apis/60412
**Category:** Elasticsearch
**Created:** [September 13, 2016, 5:12pm UTC](https://discuss.elastic.co/t/confused-with-update-apis/60412 "2016-09-13T17:12:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kaung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaung/32/11165_2.png) [@kaung](https://discuss.elastic.co/u/kaung)
#### Post date: [September 13, 2016, 5:12pm UTC](https://discuss.elastic.co/t/confused-with-update-apis/60412/1 "2016-09-13T17:12:14Z")

</div>

I am a little confused with various options in Update API. Here is a gist of what I understand:

- Scripted updates  
payload: a "script"  
result: update the doc using script. fail if doc doesn't exist
- Update with a partial doc  
payload: a "doc"  
result: merge "doc" payload into existing doc. Fail if there is no existing doc
- Upserts  
payload: a "script" and a "upsert"  
result: if no existing doc, create a doc with "upsert" content. Else, update the doc using "script"
- Scripted Upsert  
payload: a "script" only (I assumed "upsert" payload doesn't make sense here)  
result: similar to regular upsert but use "script" for both insert and update.
- doc\_as\_upsert  
payload: a "doc" only  
result: merge "doc" payload into existing doc. Create one if there is no existing doc

Did I understand them right? If yes, I am having some dilemma choosing the right options in Logstash elasticsearch plugin. My scenario is this,

- insert logstash event as a new doc if none exists
- use script to update an existing doc if one exists

I don't understand why elasticsearch update API has to define a special payload named "upsert". Isn't it simpler to interpret "doc" payload depending on context. Now, the trouble with special "upsert" payload is in Logstash elasticsearch plugin, "upsert" option accepts a string. How can I marshall the entire event into a single string?

Thanks in advance. 🙂

---

<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: [July 5, 2017, 10:20pm UTC](https://discuss.elastic.co/t/confused-with-update-apis/60412/2 "2017-07-05T22:20:33Z")

</div>


