# Logstash elasticsearch output plugin Document\_id and Upserts

**URL:** <https://discuss.elastic.co/t/logstash-elasticsearch-output-plugin-document-id-and-upserts/283909>\
**Category:** Logstash\
**Created:** [September 10, 2021, 6:50pm UTC](https://discuss.elastic.co/t/logstash-elasticsearch-output-plugin-document-id-and-upserts/283909 "2021-09-10T18:50:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkward](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pkward/32/95305_2.png) [@pkward](https://discuss.elastic.co/u/pkward)\
**Post date:** [September 10, 2021, 6:50pm UTC](https://discuss.elastic.co/t/logstash-elasticsearch-output-plugin-document-id-and-upserts/283909/1 "2021-09-10T18:50:23Z")

</div>

Question, does a customized document\_id require an upsert to update the document or can this be accomplished with just the document\_id? I've read that upserts are used if you want create a new document if the document does not exist, but I'm not sure if I'm clear on how it works.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [September 10, 2021, 7:27pm UTC](https://discuss.elastic.co/t/logstash-elasticsearch-output-plugin-document-id-and-upserts/283909/2 "2021-09-10T19:27:51Z")

</div>

By default (action =\> index), if you write a document to elasticsearch with a custom id and a document with that id already exists, then it is completely replaced by the new document.

If you set the action option to update, then if the document already exists, it is updated with fields from the event (and if it does not exist then an error is returned).

If you enable upsert then if an update is sent for a document that does not exists then elasticsearch creates it.

Does that help? If you want more detail it might be better to move this to the elasticsearch forum, since it is really a question about the [Bulk API](https://www.elastic.co/guide/en/elasticsearch/reference/7.14/docs-bulk.html), not logstash.

---

<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 8, 2021, 7:28pm UTC](https://discuss.elastic.co/t/logstash-elasticsearch-output-plugin-document-id-and-upserts/283909/3 "2021-10-08T19:28:18Z")

</div>

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