# JDBC input MS SQL

**URL:** <https://discuss.elastic.co/t/jdbc-input-ms-sql/129719>\
**Category:** Logstash\
**Created:** [April 26, 2018, 3:51pm UTC](https://discuss.elastic.co/t/jdbc-input-ms-sql/129719 "2018-04-26T15:51:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_B\_I](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@M\_B\_I](https://discuss.elastic.co/u/M_B_I)\
**Post date:** [April 26, 2018, 3:51pm UTC](https://discuss.elastic.co/t/jdbc-input-ms-sql/129719/1 "2018-04-26T15:51:28Z")

</div>

Hi, everyone!  
I try to move my data from MS SQL DB to elastic. I found JDBC plugin and it's cool =)

But I need to store in elastic only actual data that exist at this moment in SQL DB.

How can I do this correct? I mean how I can delete old recors in elastic that doesn exist in SQL anymore

---

<div class="post-metadata">

**Author:** ![yaauie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaauie/32/23363_2.png) [@yaauie](https://discuss.elastic.co/u/yaauie)\
**Post date:** [April 26, 2018, 6:05pm UTC](https://discuss.elastic.co/t/jdbc-input-ms-sql/129719/2 "2018-04-26T18:05:53Z")

</div>

This is a pretty classic data synchronisation problem, and strategies here aren't particularly limited to Logstash/Elasticsearch 🙂

- Do you have access to a transaction log, where you can _detect_ a row being deleted from the SQL DB? If so, that will be your best bet.
- Another option would be to tag each document with a "last seen" timestamp, and periodically go back and "collect" the documents that haven't been seen recently (this could be done in a separate Logstash pipeline with elasticsearch input and elasticsearch output).
- Depending on the size of your dataset and how frequently you synchronize, you may be best off simply reading the data into a new index each time you import.

---

<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:** [May 24, 2018, 6:06pm UTC](https://discuss.elastic.co/t/jdbc-input-ms-sql/129719/3 "2018-05-24T18:06:01Z")

</div>

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