# Duplication in logstash pipeline (input elasticsearch and output sql database)

**URL:** <https://discuss.elastic.co/t/duplication-in-logstash-pipeline-input-elasticsearch-and-output-sql-database/333982>\
**Category:** Logstash\
**Created:** [May 22, 2023, 7:41am UTC](https://discuss.elastic.co/t/duplication-in-logstash-pipeline-input-elasticsearch-and-output-sql-database/333982 "2023-05-22T07:41:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex\_petrov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_petrov/32/105688_2.png) [@alex\_petrov](https://discuss.elastic.co/u/alex_petrov)\
**Post date:** [May 22, 2023, 7:41am UTC](https://discuss.elastic.co/t/duplication-in-logstash-pipeline-input-elasticsearch-and-output-sql-database/333982/1 "2023-05-22T07:41:26Z")

</div>

Hi ,  
I am using elasicsearch index as my input in my logstash config and the output is jdbc-output plugin logstash that send logs to sql database table columns , and the problem is I have duplication in sql database , I used uuid filter plugin logtash but nothing changed.what is the reason and what solution do you suggest?  
here is my config :

```auto
input{
    elasticsearch {
        hosts => "ip:9200"
        index => "indexname"
        user => "user"
        password => "elastic"
        query => '{ "query": { "query_string": { "query": "*" } } }'
        schedule => "*/5 * * * *" #Specifies how often the query should be executed. In this case, it's set to run every 5 minutes
        size => 1500 #Specifies the maximum number of documents to retrieve per query
        scroll => "5m" #Specifies how long Elasticsearch should keep the search context open for the query. In this case, it's set to 5 minutes
        docinfo => true
      }
}
filter {
     uuid {
        target => "document_id"
        overwrite => true
      }
   }
	
output {
  if "API_REQUEST" in [message] {
    jdbc {
      driver_jar_path => '/usr/share/logstash/vendor/jar/jdbc/mssql-jdbc-12.2.0.jre8.jar'
      connection_string => "jdbc:sqlserver://ip:1433;databaseName=izdb;user=user;password=pass;ssl=false;trustServerCertificate=true"
      enable_event_as_json_keyword => true
      statement => [
"INSERT INTO Transaction (document_id, logLevel, timestamp) VALUES (?,?,?)",
        "document_id",
        "logLevel",
        "timestamp"
      ]
    }
  }
}
}

```

---

<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 22, 2023, 5:47pm UTC](https://discuss.elastic.co/t/duplication-in-logstash-pipeline-input-elasticsearch-and-output-sql-database/333982/2 "2023-05-22T17:47:24Z")

</div>

A uuid filter is meant to generate a unique id for each event, even if the same event is processed multiple times. It is explicitly [not meant](https://www.elastic.co/guide/en/logstash/current/plugins-filters-uuid.html#_description_162) to de-duplicate events.

If you want to overwrite the database row each time a duplicate event is processed then use a fingerprint filter to generate the id. (That assumes that INSERT will overwrite a document with the same primary key, and that very much depends on your what your DB allows.)

---

<div class="post-metadata">

**Author:** ![alex\_petrov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_petrov/32/105688_2.png) [@alex\_petrov](https://discuss.elastic.co/u/alex_petrov)\
**Post date:** [May 23, 2023, 8:27am UTC](https://discuss.elastic.co/t/duplication-in-logstash-pipeline-input-elasticsearch-and-output-sql-database/333982/3 "2023-05-23T08:27:35Z")

</div>

Hi badger,  
that' s exactly true. I just add docinfo\_target =\> "[@metadata][doc]" in elasticsearch input and used [@metadata][doc][\_id] instead of document\_id in output and the problem solved.  
thank you.

---

<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 20, 2023, 8:28am UTC](https://discuss.elastic.co/t/duplication-in-logstash-pipeline-input-elasticsearch-and-output-sql-database/333982/4 "2023-06-20T08:28:08Z")

</div>

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