# Logstash update if id matches

**URL:** <https://discuss.elastic.co/t/logstash-update-if-id-matches/186472>\
**Category:** Logstash\
**Created:** [June 19, 2019, 1:11pm UTC](https://discuss.elastic.co/t/logstash-update-if-id-matches/186472 "2019-06-19T13:11:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aymen\_Ben\_Moussa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aymen_ben_moussa/32/44513_2.png) [@Aymen\_Ben\_Moussa](https://discuss.elastic.co/u/Aymen_Ben_Moussa)\
**Post date:** [June 19, 2019, 1:11pm UTC](https://discuss.elastic.co/t/logstash-update-if-id-matches/186472/1 "2019-06-19T13:11:44Z")

</div>

is there a possibility to update a document if id matches else insert ?  
Alright i'm reading a kafka topic and this a sample of my topic

`

`> "schema":{"type":"struct","fields":[{"type":"string","optional":true,"field":"name"},{"type":"string","optional":true,"field":"season"},{"type":"string","optional":true,"field":"id"}],"optional":false,"name":"mongo_conn.test.testCollection"},"payload":{"name":"aothertest","season":"reallyweird","id":"5d0a2a75baff7c1e89ef44d3"}}`

`

ps: all i need is found under payload [name,season,id]

and this is my logstash input

> ```
> input {
> kafka {
> bootstrap_servers => "localhost:9092"
> topics => "mongo_conn.test.testCollection"
> auto_offset_reset => "earliest"
> codec => json{}
> }
> }
> 
> ```

for example incase if payload.id matches a already existing payload.id , update the document

---

<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:** [June 19, 2019, 1:20pm UTC](https://discuss.elastic.co/t/logstash-update-if-id-matches/186472/2 "2019-06-19T13:20:13Z")

</div>

If you are using an elasticsearch output then you can use [doc\_as\_upsert](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-doc_as_upsert).

---

<div class="post-metadata">

**Author:** ![Aymen\_Ben\_Moussa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aymen_ben_moussa/32/44513_2.png) [@Aymen\_Ben\_Moussa](https://discuss.elastic.co/u/Aymen_Ben_Moussa)\
**Post date:** [June 19, 2019, 1:56pm UTC](https://discuss.elastic.co/t/logstash-update-if-id-matches/186472/3 "2019-06-19T13:56:43Z")

</div>

@Badger I've added that, but nothing happens it keeps on pushing the update as a new insert maybe i need to specify the id nested in payload ? as i mentioned before all my info are inside payload the rest i don't need it's just the way the format is in kafka

---

<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:** [June 19, 2019, 2:12pm UTC](https://discuss.elastic.co/t/logstash-update-if-id-matches/186472/4 "2019-06-19T14:12:12Z")

</div>

You are using

```
document_id => "%{[payload][id]}"

```

right?

---

<div class="post-metadata">

**Author:** ![Aymen\_Ben\_Moussa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aymen_ben_moussa/32/44513_2.png) [@Aymen\_Ben\_Moussa](https://discuss.elastic.co/u/Aymen_Ben_Moussa)\
**Post date:** [June 19, 2019, 2:21pm UTC](https://discuss.elastic.co/t/logstash-update-if-id-matches/186472/5 "2019-06-19T14:21:03Z")

</div>

@Badger much love, no i was not using that i just tested it and it's working fine, i have a question thought what about the action =update thing ?

---

<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:** [June 19, 2019, 2:42pm UTC](https://discuss.elastic.co/t/logstash-update-if-id-matches/186472/6 "2019-06-19T14:42:40Z")

</div>

I believe if you are setting doc\_as\_upsert then you should be using action =\> "update".

---

<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 17, 2019, 2:42pm UTC](https://discuss.elastic.co/t/logstash-update-if-id-matches/186472/7 "2019-07-17T14:42:49Z")

</div>

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