# Same data keeps on adding which results in duplicate data while using jdbc to fetch data from the mysql server

**URL:** <https://discuss.elastic.co/t/same-data-keeps-on-adding-which-results-in-duplicate-data-while-using-jdbc-to-fetch-data-from-the-mysql-server/166574>\
**Category:** Logstash\
**Created:** [January 31, 2019, 2:02pm UTC](https://discuss.elastic.co/t/same-data-keeps-on-adding-which-results-in-duplicate-data-while-using-jdbc-to-fetch-data-from-the-mysql-server/166574 "2019-01-31T14:02:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachin\_augustine](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@sachin\_augustine](https://discuss.elastic.co/u/sachin_augustine)\
**Post date:** [January 31, 2019, 2:02pm UTC](https://discuss.elastic.co/t/same-data-keeps-on-adding-which-results-in-duplicate-data-while-using-jdbc-to-fetch-data-from-the-mysql-server/166574/1 "2019-01-31T14:02:11Z")

</div>

how can i avoid same data to pass and add up to the previous data creating redundancy

for example when I add doc A and B, and then later when I add C, then doc A, B again along with C gets added to the elastic search thus creating A,B,A,B,C......

input {  
jdbc {  
jdbc\_driver\_library =\> "/home/sachin/jdbc/mysql-connector-java-5.1.47/mysql-connector-java-5.1.47-bin.jar"  
jdbc\_driver\_class =\> "com.mysql.jdbc.Driver"  
jdbc\_connection\_string =\> "jdbc:mysql://localhost:3306/pepipayment"  
jdbc\_user =\> "root"  
jdbc\_password =\> "Root@123"  
schedule =\> "\* \* \* \* \*"  
statement =\> "SELECT \* from pepi\_pay"  
}  
}

filter {  
mutate {convert =\> ["trid", "integer"]}  
mutate {convert =\> ["clientid", "integer"]}  
mutate {convert =\> ["amount", "integer"]}  
mutate {convert =\> ["invoice1", "integer"]}  
mutate {convert =\> ["status", "integer"]}

}

output {  
elasticsearch {  
hosts =\> "localhost"  
index =\> "trans\_pay"  
document\_type =\> "pay"  
}  
stdout {  
codec =\> rubydebug  
}  
}

---

<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:** [January 31, 2019, 2:27pm UTC](https://discuss.elastic.co/t/same-data-keeps-on-adding-which-results-in-duplicate-data-while-using-jdbc-to-fetch-data-from-the-mysql-server/166574/2 "2019-01-31T14:27:12Z")

</div>

If your database has either a sequence column or a timestamp that indicates the last update time then the jdbc input can handle [state](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html#_state). If you search the logstash forum for sql\_last\_value you should be able to find some examples.

---

<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:** [February 28, 2019, 2:27pm UTC](https://discuss.elastic.co/t/same-data-keeps-on-adding-which-results-in-duplicate-data-while-using-jdbc-to-fetch-data-from-the-mysql-server/166574/3 "2019-02-28T14:27:12Z")

</div>

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