# Delete lines in Elasticsearch previous deleted in SQL DB

**URL:** <https://discuss.elastic.co/t/delete-lines-in-elasticsearch-previous-deleted-in-sql-db/183281>\
**Category:** Logstash\
**Created:** [May 29, 2019, 8:56am UTC](https://discuss.elastic.co/t/delete-lines-in-elasticsearch-previous-deleted-in-sql-db/183281 "2019-05-29T08:56:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francisca\_Lima](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@Francisca\_Lima](https://discuss.elastic.co/u/Francisca_Lima)\
**Post date:** [May 29, 2019, 8:56am UTC](https://discuss.elastic.co/t/delete-lines-in-elasticsearch-previous-deleted-in-sql-db/183281/1 "2019-05-29T08:56:48Z")

</div>

Hello,  
In my logstash file, I input my data from a mysql database and then do some transformations and insert in elasticsearch. I used the action update to always have the most updated information. However, if I delete some lines of mysql database, how I can delete those lines from elasticsearch?

Thank you,  
Francisca

---

<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:** [May 29, 2019, 12:17pm UTC](https://discuss.elastic.co/t/delete-lines-in-elasticsearch-previous-deleted-in-sql-db/183281/2 "2019-05-29T12:17:36Z")

</div>

> [@Francisca\_Lima](#):
>
> However, if I delete some lines of mysql database, how I can delete those lines from elasticsearch?

You might be able to do it using an AFTER DELETE trigger in MySQL.

---

<div class="post-metadata">

**Author:** ![Francisca\_Lima](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@Francisca\_Lima](https://discuss.elastic.co/u/Francisca_Lima)\
**Post date:** [May 30, 2019, 5:05pm UTC](https://discuss.elastic.co/t/delete-lines-in-elasticsearch-previous-deleted-in-sql-db/183281/3 "2019-05-30T17:05:09Z")

</div>

Thank you. However, from the side of logstash what can I do?

---

<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:** [May 30, 2019, 7:54pm UTC](https://discuss.elastic.co/t/delete-lines-in-elasticsearch-previous-deleted-in-sql-db/183281/4 "2019-05-30T19:54:23Z")

</div>

Well, it is possible. You could use an elasticsearch input to read all the documents, then use a jdbc\_streaming to look them up in MySQL. If you find it in the DB then drop {} the event, otherwise send it to an elasticsearch output with the action option set to delete.

You would need to be careful around error handling. A database error will result in you deleting records from elasticsearch. It sounds really fragile to me.

---

<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:** [June 27, 2019, 7:54pm UTC](https://discuss.elastic.co/t/delete-lines-in-elasticsearch-previous-deleted-in-sql-db/183281/5 "2019-06-27T19:54:28Z")

</div>

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